Git: top interview questions for DevOps

Nov 12, 2022 · 5 mins read · Post a comment

Preparing and passing technical DevOps interviews is a skill by itself. Although I didn’t encounter many Git-related questions since mostly the focus is put on the CI/CD cycle, there are a dozen Git questions you might want to get prepare for. Most interviewers google these questions as well. However, here’s my list of most essential ones in no particular order.

Repo and repository are used interchangeably.


  • Git


1. What is Git?

Git is a distributed version control system (VCS) and open-source tool written in C that helps with a project team development contribution by tracking file changes whatever being part of a small or large project.

2. What is a Git repository and how to create one?

A git repo is a folder that contains all project files and their changes (metadata) stored under a hidden directory named .git. To initialize a repository, run: git init.

3. What is a bare repo?

A bare repository is a Git repo that contains the .git subdirectory only, without any project-related files whatsoever.

4. What is Git commit and how to list all Git commits?

Git commit is basically a snapshot of all current files that are being part of the index (the staging area). To list all Git commits, run: git log.

Related: How to list all commits in a Git repository.

5. What is Git conflict and how do you usually resolve one?

Git conflict is an event that happens when there are two or more updates applied on the same line of code, so Git can’t automatically decide which changes to keep. Overall, it occurs during merging Pull Requests, rebasing and cherry-picking branches.

Resolving Git conflict steps:
5.1. Open the conflicting files in your favorite IDE.
5.2. Decide on which changes to keep.
5.3. Save the file(s).
5.4. Create a new commit and push changes.
5.5. A new merge commit will be created.

6. Name some common Git commands and briefly explain them.

  • git clone = download repo.
  • git init = initialize a repository.
  • git checkout = switching to another branch or commit.
  • git add = stage modified files to the index.
  • git commit = commit changes.
  • git push = push changes to remote.
  • git log = list whole Git commit history.
  • git reflog = list local Git commit history only.
  • git merge = updates another branch code by integrating changes from another one.
  • git cherry-pick = checkout commit hence leading to detached HEAD state.

7. What’s the difference between git merge and git rebase?

git merge is a Git commit that take changes from one branch and merges into another. Preserves history.

Where git rebase moves, relocate commits from one branch onto a new base commit.

Related: Git: merge vs rebase.

8. What’s the difference between git fetch and git pull?

git fetch pulls metadata only from the remote repository without downloading file changes if any.

git pull = git fetch + git merge. Checks for any changes by pulling the metadata. Then, updates code by downloading and merging changes.

9. Which branching strategies can you name?

GitFlow = outdated, branches included: master, develop, feature, release and hotfix.

GitHub Flow = modern approach. The branch flow being: featuremain, or featuredevelopmain.

GitLab Flow = addressing issues known in the other two by introducing environments per branch and a production branch that’s protected and isolated from the main and the rest.

TBD = one trunk (main) branch and multiple feature short-lived ones. Perfectly aligns with the true Agile DevOps CI/CD practices.

Related: Git 101: branching strategies.

10. What is the difference between HEAD, working tree and index?

HEAD = pointer that points to the current checked out branch / commit.

working tree = the folder that consists of the .git subdirectory and all other project-related files and folders. Think of it as the working directory.

Index also called the staging area is the place where all modified, git-tracked files are stored. Namely, every git add-ed file is part of the staging area.

Related: Git: HEAD vs working tree vs index.

11. What is cherry-picking in Git?

git cherry-pick is a command that allows you to apply any commit to the current HEAD. This state is also known as a *headless state.

Generally, useful for hotfixing bugs and recovering removed or lost commits.

Related: Cherry picking commits in Git.


If you have any to add from your personal experience (not from some other blogs) please share them in the comment section below.

To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.