Git
Rebase
Conflict Resolution
Version Control
HEAD

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.

Browse interview questions

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:

text
main:    A -- B -- C
feature:          D -- E

If you run:

bash
git checkout feature
git rebase main

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:

text
1<<<<<<< HEAD
2code from the branch you are rebasing onto
3=======
4code from the commit currently being replayed
5>>>>>>> 1234abcd

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:

  • '--ours means the branch you are rebasing onto.'
  • '--theirs means 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:

bash
git status

Git will tell you which commit is being applied and which files are unmerged.

To inspect the patch Git is trying to replay:

bash
git rebase --show-current-patch

You can also inspect REBASE_HEAD directly:

bash
git show REBASE_HEAD

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:

bash
git add path/to/file
git rebase --continue

If you want to discard the rebased-on version for one file and keep the patch being replayed:

bash
git checkout --theirs path/to/file
git add path/to/file
git rebase --continue

If you want the upstream side instead:

bash
git checkout --ours path/to/file
git add path/to/file
git rebase --continue

And if the rebase is going badly:

bash
git rebase --abort

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:

  • 'HEAD is the temporary replay result so far.'
  • 'REBASE_HEAD is 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, HEAD means 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.
  • '--ours refers to the upstream side during rebase, and --theirs refers to your replayed commit.'
  • Use git rebase --show-current-patch, git show REBASE_HEAD, and git status to understand each conflict.
  • Resolve the file, stage it, and continue with git rebase --continue.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.