Git Interview Questions
1 test · 10 questionsStudy guides
About these Git questions
Almost every software job uses Git, so almost every technical interview touches it, often in a form like "you did this by mistake, now what?" Knowing add, commit and push gets you through a normal day. Interviewers want to know whether you can recover when something goes wrong without making it worse for the rest of the team, and these questions are built around exactly those moments.
They suit developers, DevOps and platform engineers preparing for interviews, students who learned Git by copying commands, and anyone heading into a role that uses GitOps or CI/CD pipelines where the repository is the source of truth. No vendor exam is attached to them.
What the questions cover
- The three trees. The working tree, the index and
HEAD, and why plaingit diffshows only what you haven't staged yet. - Undoing changes. When
git reset --softis the cleanest way to squash local commits, and whygit revertis the right tool once a commit is on a shared branch that others have pulled. - Recovering lost work. Using the reflog to get back commits that a
reset --hardremoved fromgit log, and keeping commits made in detached HEAD state. - Merge versus rebase. Why rebasing a branch other people have built on causes trouble, and what to do instead.
- Tracking and `.gitignore`. Why ignoring a file that is already committed changes nothing, and how to stop tracking it without deleting your local copy.
- Remotes and pushing. What
--force-with-leaseprotects against, and how a background fetch by your editor can quietly remove that protection. - Moving commits. Using
cherry-pickto move a commit made on the wrong branch, then cleaning up the branch it landed on. - Debugging with Git. Automating
git bisect runover hundreds of commits, including the exit code that tells it to skip a commit that doesn't build.
How to use them
There is one practice test of 10 questions, from easy to hard. Every answer comes with an explanation of why it works, why each other option fails, and a link to the Git reference or the Pro Git book.
- Work each scenario in a scratch repository.
git init, three commits and a few minutes are enough to reproduce nearly all of them, and seeing the reflog or a detached HEAD for yourself makes it stick. - Before you pick an answer, ask what each option would do to a teammate who has already pulled. That one question rules out most of the wrong options.
- Learn to read
git statusandgit log --oneline --graph --allfluently. Most recovery starts with understanding whereHEADand each branch point right now. - Practise explaining your answer in a sentence or two. In an interview, "revert, because main is shared and rewriting it breaks everyone's clone" is the answer they want to hear.
These questions are original, written from the official Git documentation and the Pro Git book. They are not taken from any real interview or exam.