Git interview questions check whether you can track work, join a team and undo mistakes safely. These 24 Git interview questions and answers move from basics to production scenarios. For a full command list, use our Git commands guide; this page teaches what to say in an interview.
The picture behind most Git interview questions
Remember four places. A command makes sense once you know which place it changes.
| Place | What it holds | Example command |
|---|---|---|
| Working folder | Files you edit | git restore file |
| Staging area | Changes chosen for the next commit | git add file |
| Local repository | Commits and branches | git commit |
| Remote | Shared copy, such as GitHub | git push |
Pro tip: Before any undo command, ask, "Has someone else already pulled this commit?" If yes, prefer a new commit that reverses it.
Git interview questions for freshers
Q1. What is Git?
30-second answer: Git is a distributed version control system. It records changes as commits, and each normal clone has the project history. You can commit and view history without the internet.
GitHub is a service that hosts Git repositories and adds reviews, issues and automation.
Q2. What is a commit?
30-second answer: A commit records a snapshot of the project, plus its author, message and parent commit. A hash identifies it.
Git stores unchanged content again by reference, so a snapshot does not mean a full second copy every time.
Q3. What is the staging area?
30-second answer: It is where you choose what goes into the next commit. This lets you save two unrelated edits as two clear commits.
git add -p lets you choose parts of a file. git diff shows unstaged changes, and git diff --staged shows what will be committed.
Q4. What is a branch?
30-second answer: A branch is a movable name that points to a commit. When I commit on it, the name moves to the new commit.
git switch -c feature/login
git add .
git commit -m "Add login form"
git switch was added to make branch changes clearer. Older teams use git checkout -b for the same task.
Q5. What is the difference between fetch and pull?
30-second answer: Fetch downloads remote changes without changing my current branch files. Pull fetches and then joins the changes to my current branch by merge or rebase, based on options and settings.
Fetch first when you want to inspect changes.
Q6. How do you solve a merge conflict?
30-second answer: I open each conflict, understand both changes, edit the right final text, test it, stage it and finish the merge.
<<<<<<< HEAD
price = 100
=======
price = 120
>>>>>>> feature/price
Remove all markers. Do not pick one side blindly. If needed, stop with git merge --abort.
Q7. What does .gitignore do?
30-second answer: It tells Git which untracked files to ignore, such as build folders and local settings. It does not stop tracking a file that is already committed.
git rm --cached .env
This removes .env from the next commit but keeps the local file. It does not remove it from old commits.
Q8. What is git stash?
30-second answer: Stash saves unfinished changes so I can work on something else. git stash pop applies the latest stash and removes it if it applies without conflicts.
By default, stash leaves untracked files behind. Use git stash push -u to include them.
If the basics are new, set up a profile with GitHub for freshers and make daily commits.
Git interview questions for experienced developers
Q9. What is the difference between merge and rebase?
30-second answer: Merge joins histories and may create a merge commit. Rebase replays my commits on a new base and gives those new commits new hashes.
Merge keeps the branch shape. Rebase makes a straight history. I avoid rebasing commits that other people build on unless the team agrees.
Q10. What is a fast-forward merge?
30-second answer: It happens when the target branch has no new commits since the feature began. Git only moves the branch name forward.
Use --no-ff when you want a merge commit to show where a feature joined.
Q11. Compare reset, revert and restore.
30-second answer: Reset can move a branch to another commit. Revert makes a new commit that reverses an old one. Restore changes files or the staging area without moving the branch.
| Command | Best use |
|---|---|
git reset |
Change private commit history |
git revert |
Undo a shared commit |
git restore |
Discard a file edit or unstage it |
Q12. What do soft, mixed and hard reset do?
30-second answer: Soft moves the branch and keeps changes staged. Mixed, the default, keeps changes but unstages them. Hard makes the staging area and tracked files match the chosen commit.
Common mistake: Thinking reflog can recover everything after
reset --hard. It can help find old commits, but not edits that Git never saved.
Q13. What is cherry-pick?
30-second answer: It applies the change from a chosen commit as a new commit on the current branch. It is useful for moving one fix to a release branch.
Too many cherry-picks can make the same change harder to track. Merging is clearer when you need the whole branch.
Q14. What is detached HEAD?
30-second answer: It means HEAD points directly to a commit instead of a branch. I can look around and commit, but no branch name follows those commits.
To keep new work, run git switch -c saved-work before leaving.
Q15. What is the difference between two dots and three dots?
30-second answer: In git log main..feature, I see commits reachable from feature but not main. In git diff main...feature, I see changes from their common starting point to feature.
The meaning of dots differs between log and diff, so name the command in your answer.
Git interview questions and answers for experienced scenario-based rounds
Q16. You deleted a commit with reset. How do you recover it?
30-second answer: I use reflog to find the old commit, then create a branch there. This keeps it safe before I decide what to do next.
git reflog
git branch recovered HEAD@{1}
git log --oneline -1 recovered
Check the number first. HEAD@{1} is right only if the reset was your last HEAD move. Reflog is local and entries can expire.
Q17. A bad commit is already on main. What do you do?
30-second answer: I revert it, test the result and push the new commit through the usual process.
git revert <commit>
To revert a merge commit, choose the parent line to keep, often -m 1. A later merge of the same branch will not bring those changes back by itself. You may need to revert the revert.
Q18. You committed to main instead of a feature branch. Fix it.
30-second answer: If it is one unpushed commit, I create a branch at that commit and move main back one commit.
git branch feature/login
git reset --hard HEAD~1
git switch feature/login
Run git status first. Hard reset would remove other uncommitted tracked edits. If the commit was pushed, use a new branch and a revert instead.
Q19. A password was pushed. What is your first step?
30-second answer: Revoke or rotate the password at once. Then remove it from the code, tell the right team, check for misuse and decide whether to clean the history.
Deleting it in a new commit does not remove it from old commits, forks or clones. A history rewrite with a tool such as git filter-repo needs a team plan.
Q20. A bug appeared somewhere in 200 commits. How do you find it?
30-second answer: I use bisect, which does a binary search between a good and a bad commit. A test script can run it automatically.
git bisect start
git bisect bad HEAD
git bisect good v1.4.0
git bisect run ./test.sh
git bisect reset
The script should return 0 for good and normally 1 for bad. Code 125 means skip a version that cannot be tested.
Git interview questions for 5 years experience
Q21. Which branching model would you choose?
30-second answer: For a web app released often, I prefer short branches merged into main with automated tests. For products that support many versions, release branches may be needed.
Say what drives the choice: release speed, supported versions, team size and test quality. Name a model only after that. Read about daily teamwork in GitHub collaboration basics.
Q22. Is force push ever safe?
30-second answer: It can be fine on my own branch after a rebase. I use git push --force-with-lease and block force pushes on shared branches.
With lease, Git refuses if the remote branch is not where it expects. A background fetch can update that expectation, so check before pushing.
Git interview questions and answers for DevOps engineer roles
Q23. How do tags and releases work in a pipeline?
30-second answer: The team tags a tested commit, and the pipeline builds or promotes a release from it. An annotated tag stores a message, date and tagger.
git tag -a v1.4.0 -m "Release 1.4.0"
git push origin v1.4.0
Do not move a published tag. Protect release tags so that a version always means the same code. The DevOps interview questions cover the next pipeline steps.
Q24. How do hooks and server checks differ?
30-second answer: Local hooks run on a developer's computer and give quick feedback. Server checks run on the shared system and can enforce tests, reviews and protected branches.
Local hooks can be skipped and are not copied by a normal clone. Use both, but never rely on local hooks for security. For a large repository, also mention shallow clone, partial clone and Git LFS, and explain what each one saves.
Interview note: If asked "why not run every check in a hook?", say that slow hooks push people to skip them. Keep fast checks local and full checks in CI.
A 20-minute Git practice test
Create a throwaway repository and complete these steps without copying commands.
- Make two commits on main.
- Create two branches that edit the same line.
- Merge both and fix the conflict.
- Make one bad commit and revert it.
- Reset one private commit, then recover it through reflog.
- Rebase a feature branch and explain why its hash changed.
- Add a tag and show which commit it points to.
After each step, draw the branches as boxes and arrows. Say where HEAD, main and the feature branch point. This gives you an answer even when you forget the exact option.
Use these checks to see your result:
git status -sb
git log --oneline --graph --all
git reflog -5
git show --stat HEAD
The graph command shows all local branches and other refs. git show --stat lists files changed by the latest commit. You can use both in a live interview before making a risky change.
What to say when you do not remember a command
Do not guess with a command that deletes work. Explain the safe order instead:
- Look: check status, branch and recent commits.
- Save: make a backup branch or stash changes.
- Choose: reverse a shared commit, or edit private history.
- Check: inspect the diff and run the tests.
- Share: push through the team's normal review.
For example, you might say, "I need to undo a shared merge. I would use revert, not reset. I need to check the parent option before running it." This shows judgment and honesty.
At 5 years, add one decision from your work, such as why your team squashes commits or protects main. Explain the result and the cost. For a wider developer round, continue with full stack developer interview questions.

