Git Rebase Conflict Who is HEAD?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Rebase conflicts are confusing because Git temporarily changes the meaning of "current" while it replays commits. When a conflict says HEAD, it does not mean "my original branch tip"; it means the commit state Git has checked out right now as it applies the next patch in the rebase sequence.
What HEAD means during a rebase
Normally, HEAD points to the commit you currently have checked out. During git rebase, Git detaches HEAD, checks out the new base commit, and then starts replaying your branch commits one by one on top of it.
Suppose history starts like this:
If you run:
Git checks out C first, then tries to replay D, then E. If D conflicts, HEAD points to the temporary rebased state based on C, not to the original feature tip.
Reading the conflict markers
When a file contains conflict markers during rebase:
HEAD is the "already rebased" side, which includes the upstream branch and any commits that have already been replayed successfully. The other side is the patch from the specific commit Git is trying to apply.
That is why the terms ours and theirs feel backward during rebase:
- '
--oursmeans the branch you are rebasing onto.' - '
--theirsmeans the commit from your branch that is being replayed.'
This is the opposite of what many people expect from a regular merge.
Commands that show what Git is doing
When you hit a conflict, start here:
Git will tell you which commit is being applied and which files are unmerged.
To inspect the patch Git is trying to replay:
You can also inspect REBASE_HEAD directly:
Those commands make the conflict much easier to understand because you can see the exact change Git wants to apply.
Resolving the conflict cleanly
After editing the conflicted file, stage the resolution and continue:
If you want to discard the rebased-on version for one file and keep the patch being replayed:
If you want the upstream side instead:
And if the rebase is going badly:
That restores the branch to the state it had before the rebase started.
A useful mental model
Treat rebase as "take each commit from my branch and try to replay it on top of another branch." With that model:
- '
HEADis the temporary replay result so far.' - '
REBASE_HEADis the commit currently being applied.' - Conflict markers compare the rebased base state with the patch from the current commit.
Once you adopt that model, the output stops feeling random.
Common Pitfalls
The biggest mistake is assuming HEAD means "my original feature branch." During rebase, it usually means the upstream side plus any commits already replayed.
Another common problem is using --ours and --theirs from merge muscle memory. In rebase, those names are effectively swapped relative to what many developers expect.
Do not blindly resolve every conflict by choosing one side. Rebasing can apply your changes in a different context, so sometimes the right answer is a manual merge of both versions.
Finally, check git status after every conflict resolution. It tells you whether you still have unmerged paths or whether Git is ready for git rebase --continue.
Summary
- During rebase,
HEADmeans the temporary checked-out state Git is replaying onto, not your original branch tip. - Conflict markers compare the rebased base side with the commit currently being applied.
- '
--oursrefers to the upstream side during rebase, and--theirsrefers to your replayed commit.' - Use
git rebase --show-current-patch,git show REBASE_HEAD, andgit statusto understand each conflict. - Resolve the file, stage it, and continue with
git rebase --continue.
Related reading
- git rebase error cannot stat 'file' Permission denied
- git rebase, keeping track of ''local'' and ''remote''
- Git rebase loses history, then why rebase?
- git recover deleted file where no commit was made after the delete
- git recover deleted file where no commit was made after the delete
- Git refusing to merge unrelated histories on rebase
- git remote add with other SSH port
- Git remote branch deleted, but still it appears in ''branch -a''
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.