Git Mock Interview

Updated · 11 min read
mediumGit 2.53gitinterviewmock interviewassessment

Actors don't rehearse a play by reading the script silently in a chair. They stand up, say the lines out loud, and run the scene against the clock, because that is where the forgotten words show up. Interviews work the same way. You may understand rebase perfectly, but explaining it clearly in two minutes, while someone waits, is a different skill. This page is your rehearsal: 20 Git questions of the kind interviewers ask, 40 minutes on the clock, and a model answer to compare with after each one.

How the Mock Interview Works

  1. Press Start on the timer below. You have 40 minutes for 20 questions, so about 2 minutes each.
  2. Read a question and answer it out loud, as if an interviewer were sitting across from you. Don't open the model answer first.
  3. Open the model answer and compare it with what you said.
  4. Mark yourself honestly: Strong if you covered all the key points, Partial if you got some of them, Missed if you didn't know.
  5. Move on, even if you are unhappy with an answer. In a real interview there's no going back either.

Target: 14 or more answers marked Strong. Your score appears at the bottom of the page as you mark.

Mock interview: 40 minutes

Press Start, then answer question 1 out loud. Aim for about 2 minutes per question.

The 20 Questions

1. Git in One Minute

Explain Git to someone who has never used version control.

Model answer

Git records the history of a project as a series of snapshots called commits. Each commit says who changed what, when and why, so you can see any earlier version, find when something broke, and undo mistakes. Branches let several people, or several ideas, move forward in parallel and be combined later. And because every developer has a full copy of the history, most work is fast and works offline; a server such as GitHub is used to share it. Revise: What Is Git.

Your mark for question 1

2. Three Areas of Git

What happens, step by step, between editing a file and having it in a commit?

Model answer

You edit the file in the working tree. git add stores the file's current content as a blob and records it in the staging area (the index), which is the draft of the next commit. git commit turns the index into tree objects, creates a commit pointing to the top tree and to the parent commit, and moves the current branch to it. Because staging is separate, you can commit only part of your changes and build focused commits. Revise: Working Tree, Staging Area and Repository.

Your mark for question 2

3. Undo Choices

You made a mistake. How do you choose between restore, reset and revert?

Model answer

It depends on where the mistake is. Uncommitted changes in a file: git restore <file> (or --staged to unstage). Commits that are only on my machine: git reset, --soft to keep the changes staged, --mixed to keep them unstaged, --hard to throw them away. Commits already pushed and shared: git revert, which adds a new commit that undoes them without rewriting history. The rule: never rewrite history others already have. Revise: How to Undo Changes in Git.

Your mark for question 3

4. What a Branch Really Is

What is a branch, and why are branches cheap in Git?

Model answer

A branch is a name that points to a commit, stored as a tiny file containing a commit ID (or a line in packed-refs). HEAD points to the current branch, and each new commit moves that branch forward. Creating a branch copies nothing, it writes one ID, so teams create branches for every feature and fix and delete them after merging. Revise: Git Branch.

Your mark for question 4

5. Fast-Forward or Merge Commit

When does a merge create a merge commit, and when doesn't it?

Model answer

If the branch I merge into hasn't moved since the other branch started, Git can fast-forward: it just moves the pointer, and history stays a straight line. If both branches have new commits, Git does a three-way merge and records a merge commit with two parents. --no-ff forces a merge commit even when a fast-forward is possible, which keeps a feature's commits grouped; --ff-only refuses anything but a fast-forward. Revise: Fast-Forward vs Merge Commit.

Your mark for question 5

6. Resolving a Merge Conflict

Walk me through resolving a merge conflict.

Model answer

First, git status to see which files conflict. In each file, Git marks the conflicting part with <<<<<<< HEAD (our version), ======= and >>>>>>> (their version); with merge.conflictStyle zdiff3 it also shows the common base, which helps a lot. I decide what the correct result is, which may combine both sides, remove the markers, build and run the tests, git add the file, and git commit (or git rebase --continue). If it gets messy, git merge --abort starts over. Revise: Resolving Merge Conflicts.

Your mark for question 6

7. Fetch and Pull

What is the difference between git fetch and git pull, and which do you prefer?

Model answer

fetch downloads new commits and updates remote-tracking branches like origin/main, without touching my branch or files. pull is a fetch followed by a merge or rebase into my current branch. I often fetch first and look with git log --oneline main..origin/main, then integrate deliberately; for daily updates I use git pull --rebase (or pull.rebase true) to keep my unpushed commits on top. Revise: Git Fetch.

Your mark for question 7

8. Rejected Push

Your push is rejected as non-fast-forward. What does it mean, and what do you do?

Model answer

The remote branch has commits I don't have, usually because a teammate pushed first. Accepting my push would delete their work, so Git refuses. I run git pull --rebase (or a merge), resolve any conflicts, run the tests and push again. I don't use --force; if I ever need to force-push my own rewritten branch, I use --force-with-lease. Revise: Common Git Errors: Push and Pull.

Your mark for question 8

9. Merge or Rebase

When would you rebase and when would you merge?

Model answer

Rebase my own, unshared feature branch onto the latest main to keep a clean, linear history and make review easy; merge (often through a pull request) to bring finished work into shared branches, which preserves what happened. The golden rule: don't rebase commits others already have, because rebasing creates new commits with new IDs and their copies no longer match. Teams pick a policy, such as rebase-then-merge or squash-merge, and stick to it. Revise: Merge vs Rebase.

Your mark for question 9

10. Cleaning Up Before a Pull Request

Your branch has ten messy commits. How do you clean it up before review?

Model answer

git rebase -i main opens a to-do list of my commits. I reorder them, squash or fixup small fixes into the commit they belong to, reword unclear messages and drop mistakes, ending with a few commits that each make sense. During work, git commit --fixup=<commit> plus --autosquash does most of this automatically. Then I push with --force-with-lease, since the branch was rewritten. Revise: Interactive Rebase.

Your mark for question 10

11. Cherry-Pick

What is git cherry-pick, and when is it the right tool?

Model answer

It copies the changes of one or more existing commits onto the current branch as new commits. It is right for backporting a bug fix from main to a release branch, or rescuing one commit from a branch that won't be merged. -x records the original commit ID in the message. It is the wrong tool for moving whole branches, because duplicated commits make later merges confusing; use merge or rebase for that. Revise: Git Cherry-Pick.

Your mark for question 11

12. Recovering Lost Work

A colleague ran git reset --hard and lost a day of commits. Can you help?

Model answer

Almost certainly, if the work was committed. Commits aren't deleted by a reset, only unreferenced. git reflog lists every position HEAD has had; I find the entry before the reset and run git branch rescue <id> or git reset --hard <id>. Unreachable commits survive for weeks before garbage collection. If they had only staged the work, git fsck --lost-found can find the blobs; work that was never added is gone. Revise: Git Reflog.

Your mark for question 12

13. Finding the Bad Commit

A test started failing somewhere in the last 300 commits. How do you find the cause?

Model answer

git bisect: mark the current commit bad and a known older commit good, and Git checks out the middle commit for me to test. Each answer halves the range, so 300 commits take about 9 steps. Even better, git bisect run <script> tests automatically, using the script's exit code (0 good, 1 to 127 bad, 125 skip). Then I read the guilty commit with git show and its pull request. Revise: Git Bisect.

Your mark for question 13

14. Workflows

Which branching workflow would you choose for a web application deployed several times a day?

Model answer

GitHub Flow or trunk-based development: short-lived branches from main, small pull requests with required reviews and CI, and main always deployable, with feature flags to hide unfinished work. Gitflow, with long-lived develop and release branches, suits products with scheduled, versioned releases, not continuous deployment. Whatever the choice, protect main and keep branches short. Revise: Git Workflows: GitHub Flow, Gitflow and Trunk-Based.

Your mark for question 14

15. How a Commit Is Stored

How does Git store a commit internally?

Model answer

As objects in a content-addressed store, each named by the hash of its contents. File contents are blobs; folders are trees listing names, modes and the IDs of blobs and subtrees; a commit stores the top tree's ID, the parent IDs, author, committer and message. A commit is therefore a full snapshot, with unchanged files simply pointing to existing blobs. Because a commit's ID covers its parents' IDs, changing any old commit changes every later ID. Revise: Git Objects: Blob, Tree, Commit and Tag.

Your mark for question 15

16. Large Repositories

Cloning your company's repository takes 30 minutes. What can you do?

Model answer

First measure what is big (git count-objects -vH, and the largest blobs in history). Then: a blobless partial clone (--filter=blob:none) so old file contents are fetched only when needed; sparse checkout for the folders I work on; --depth 1 for CI builds; Git LFS for large binary files, migrating old ones if needed; and git maintenance or scalar to keep it fast locally. Long term, block large files from being committed. Revise: Shallow and Partial Clones.

Your mark for question 16

17. Sharing Code Between Repositories

Two applications share some code. Submodule, subtree or package?

Model answer

For versioned libraries, especially in Java, a package through Maven or Gradle is best: clear versions and no Git tricks. A submodule pins another repository at an exact commit; it is precise but every clone needs --recurse-submodules and updates need care. A subtree copies the code into a folder, so clones need nothing extra, and git subtree can still pull and push changes. I would use a subtree or submodule only for unpackaged things like shared configuration. Revise: Git Submodules.

Your mark for question 17

18. Leaked Secret

Someone pushed an API key to the repository. What do you do?

Model answer

First, revoke or rotate the key at its provider immediately, because once pushed it must be treated as compromised. Then remove it from the code and read it from an environment variable, rewrite history with git filter-repo to remove it from every commit, force-push, and have everyone re-clone; ask the platform to clear cached references if needed. Prevent it next time with .gitignore, a secret scanner in a pre-commit hook and CI, and push protection. Revise: Keeping Secrets Out of Git.

Your mark for question 18

19. Trusting History

How can a team be sure a commit really came from the person named on it?

Model answer

They can't from the author field alone, because Git records whatever name it is given. Signed commits solve it: each developer signs with an SSH or GPG key (gpg.format ssh, user.signingKey, commit.gpgSign true), uploads the public key to the hosting platform, and the platform shows "Verified". Branch protection can require signed commits. Locally, git log --show-signature or git verify-commit checks them against an allowed signers file. Revise: Signing Commits and Tags.

Your mark for question 19

20. What Is Changing in Git

What do you know about recent and upcoming changes to Git?

Model answer

Recent: switch and restore split checkout's two jobs; --force-with-lease and --force-if-includes make force pushing safe; ort is the default merge strategy; git maintenance, sparse checkout and partial clone help large repositories; SSH signing; and git config get and set. Planned for Git 3.0, with no release date yet: SHA-256 object IDs and the reftable ref format for new repositories, main as the default branch, and removal of old commands such as git whatchanged. checkout stays. Revise: Git 3.0: What Is Planned.

Your mark for question 20

Your Score

Your mock interview score

Mark your answers above, and your score appears here.

Strong answersWhat it meansWhat to do next
17 to 20Interview readyBook real interviews, and rehearse the scenarios on 15 Git Scenario Interview Questions
14 to 16Nearly thereReread the model answers you marked Partial or Missed, then take the mock interview again in a few days
Under 14Not yetWork through 50 Git Interview Questions and Answers and the lessons linked from your weaker answers, then try again

Was this tutorial helpful?