FoundationGit

What is the difference between git merge and git rebase, and when would you use each?

What they are really testing: Every DevOps engineer teaches this to developers, so they want to hear you explain it clearly. The real test is whether you know the golden rule about shared branches.

A real interview question

What is the difference between git merge and git rebase, and when would you use each?

What most people say

drag me

Rebase gives you a cleaner history so it is better.

It picks a side without understanding the cost. Someone who believes rebase is simply better will eventually rewrite a shared branch and break the working copies of everyone on the team.

The follow-ups they ask next

  • What does a squash merge do differently?

    It collapses the whole branch into one commit on main. Great for a tidy main and simple reverts, but it discards the individual commits, which hurts when you later bisect a large change.

  • Someone rebased main and force-pushed. What now?

    Communicate immediately so nobody pushes on top. Then everyone resets their local main to the remote, and anyone with unpushed work rebases it on the new main or cherry-picks it across.

What the interviewer is listening for

  • States the shared-branch rule unprompted
  • Explains that rebase creates new hashes
  • Has a clear personal workflow

What sinks the answer

  • Declares one universally better
  • Unaware of the force-push hazard
  • Cannot explain what a merge commit is

If you genuinely do not know

Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.

Merge [creates a merge commit and preserves real history]. Rebase [replays commits on the target, making new hashes and a linear history]. The rule is [never rebase a branch others have pulled]. I [rebase my own feature branch, then merge it into main].

Keep going with git

All 87 devops engineer questions

Knowing the answer is not the same as recalling it under pressure

Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.

Start free