Git Interview Questions

Git Interview Questions

Git Beginner

What is the difference between git pull and git fetch?
Shortly, git pull = git fetch + git merge

When you run git pull, it gets all the changes from the remote or central
repository and attaches it to your corresponding branch in your local repository.

git fetch gets all the changes from the remote repository, stores the changes in
a separate branch in your local repository

Explain the following: git directory, working directory and staging area

The Git directory is where Git stores the meta data and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.

This answer taken from [](

How to resolve git merge conflicts?
First, you open the files which are in conflict and identify what are the conflicts.
Next, based on what is accepted in your company or team, you either discuss with your
colleagues on the conflicts or resolve them by yourself
After resolving the conflicts, you add the files with `git add [file_name]`
Finally, you run `git rebase --continue`

What is the difference between git reset and git revert?
git revert creates a new commit which undoes the changes from last commit.
git reset depends on the usage, can modify the index or change the commit which the branch head
is currently pointing at.

You would like to move forth commit to the top. How would you achieve that?
Using git rebase> command

In what situations are you using git rebase?

What merge strategies are you familiar with?

Mentioning two or three should be enough and it's probably good to mention that 'recursive' is the default one.


This page explains it the best:

How can you see which changes have done before committing them?

git diff

How do you revert a specific file to previous commit?
git checkout HEAD~1 -- /path/of/the/file

What is the .git directory? What can you find there?

What are some Git anti-patterns? Things that you shouldn't do

  * Not waiting to long between commits
  * Not removing the .git directory :)
Advanced Git

Explain Git octopus merge

Probably good to mention that it's:

  * It's good for cases of merging more than one branch (and also the default of such use cases)
  * It's primarily meant for bundling topic branches together 

This is a great article about Octopus merge: