Founding prices until 15 December: 30% off Pro, locked for life. See pricing

Git interview questions

2 questions. Merge vs rebase and undoing a bad commit on a shared branch. Each has a strong answer of about a minute and the points an interviewer listens for.

  1. 01

    What's the difference between git merge and git rebase, and when would you avoid rebasing?

    A strong answer

    Merge combines two branches and records a merge commit, so the history shows exactly what happened, including when branches diverged. Rebase replays your commits on top of the other branch, creating new commits, so the history is linear and easier to read. Because rebase rewrites commits, I wouldn't rebase a branch others have already pulled, like main or a shared feature branch, since they'd have to force-push or untangle duplicates. For my own local branch before opening a pull request, rebasing is fine.

    What the interviewer listens for

    • Merge joins histories with a merge commit. The basic behaviour of merge.
    • Rebase replays commits on top of another branch. The basic behaviour of rebase, and why history looks linear.
    • Don't rebase shared branches. Rewriting history others have pulled causes pain. This is the key rule.

    Likely follow-up: “You rebased and pushed with --force, and a teammate lost work. How do you recover it?”

    Practise answering it
  2. 02

    You pushed a commit to main that broke the build. How do you undo it?

    A strong answer

    Since main is shared, I'd use git revert on that commit: it creates a new commit that undoes the change, so the build is fixed and nobody's history is rewritten. I wouldn't git reset and force-push main, because everyone who pulled would end up with a broken history. I'd tell the team in the channel, then fix the actual bug in a new pull request and merge it normally.

    What the interviewer listens for

    • Use git revert on a shared branch. Revert adds a new commit that undoes the change, without rewriting shared history.
    • Avoid reset and force-push on main. Interviewers check that you know why reset is wrong on a shared branch.
    • Communicate and then fix properly. Let people know, then fix the real problem in a normal change.

    Likely follow-up: “When is git reset the right tool?”

    Practise answering it

Ready for the real thing?

A timed interview asks questions like these one at a time, adds quick questions, a design and a hands-on task on a real machine, and ends with a hire or no-hire scorecard.

Take a practice interview