Why a Rebase Stops
A rebase replays your commits one at a time on top of another branch. If one of them changes lines that the other branch also changed, Git cannot replay it on its own. It stops at that commit, leaves conflict markers in the file and waits for you. The commits before it are already replayed; the ones after it are still waiting.
You resolve each stop the way you resolve a merge conflict. The difference is that a rebase can stop more than once, once for each commit that conflicts.
Where Am I?
git status during a rebase tells you exactly where you are:
interactive rebase in progress; onto a79cdcf
Last commands done (2 commands done):
pick 9cf995b # Add packing list
pick 8f44b56 # Add river walk
Next command to do (1 remaining command):
pick 6e45133 # Pack an umbrella
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'extras' on 'a79cdcf'.
This is illustrative output; your IDs will differ.
- Git says "interactive rebase" even for a plain
git rebase: it uses the same machinery. You can ignore the word here. - Last commands done ends with the commit that stopped, here "Add river walk".
- Next command to do lists the commits still to be replayed.
- Below that, "Unmerged paths" lists the conflicted files as
both modified.
Which Side Is Which
In a rebase, the markers can look backwards:
<<<<<<< HEADintroduces the version from the branch you are rebasing onto, plus your commits replayed so far. During a rebase, HEAD is the new base being built, not your original branch.>>>>>>>is followed by the ID and message of your commit being replayed, and its version comes just before that line.
When you resolve, the question is the same as in a merge: what should the file say once both changes are included?
Three Ways Forward
git rebase --continue # after resolving and staging: replay the rest
git rebase --skip # drop the commit that stopped, then carry on
git rebase --abort # stop and put the branch back as it was
- Continue is the normal path. Resolve the file, check it with
git diff --check, stage it withgit add, then continue. Git opens your editor with the commit's message so you can adjust it; save and close. The rebase carries on and may stop again at a later commit. - Skip throws away the stopped commit's changes entirely. Use it only when that commit is no longer needed, for example because the other branch already contains the same change. Otherwise you lose work.
- Abort is always safe. Your branch returns to exactly the commit it was on before the rebase started, as if nothing had happened.
Exercise: Finish a Rebase That Stops on a Conflict
The extras branch has three commits for a trip plan. The second edits the
Day 2 line, and meanwhile main changed that line too.
Starting state: Git configured as in the configuration lesson.
-
Run the setup:
mkdir -p ~/git-practice/rebase-conflict cd ~/git-practice/rebase-conflict git init -b main cat > plan.md <<'EOF' # Trip plan Day 1: Arrive Day 2: Museum Day 3: Market Day 4: Leave EOF git add plan.md git commit -m "Add trip plan" git switch -c extras cat > packing.md <<'EOF' Bring a camera. EOF git add packing.md git commit -m "Add packing list" cat > plan.md <<'EOF' # Trip plan Day 1: Arrive Day 2: Museum and river walk Day 3: Market Day 4: Leave EOF git commit -am "Add river walk" cat >> packing.md <<'EOF' Bring an umbrella. EOF git commit -am "Pack an umbrella" git switch main cat > plan.md <<'EOF' # Trip plan Day 1: Arrive Day 2: Art gallery Day 3: Market Day 4: Leave EOF git commit -am "Swap museum for gallery" git switch extras -
Rebase
extrasontomain:git rebase mainThe first commit replays cleanly. Then Git reports
CONFLICT (content): Merge conflict in plan.mdandcould not applyfor "Add river walk". -
Find out where the rebase stopped:
git status"Last commands done" ends with "Add river walk", "Next command to do" lists "Pack an umbrella", and
plan.mdisboth modified. -
Read the conflict:
cat plan.md<<<<<<< HEAD Day 2: Art gallery ======= Day 2: Museum and river walk >>>>>>> 8f44b56 (Add river walk)The
HEADside ismain's new version; the other side is your commit. -
Both changes are wanted: the gallery from
mainand your river walk. Resolve, check, stage and continue. When the editor opens with "Add river walk", save and close it:cat > plan.md <<'EOF' # Trip plan Day 1: Arrive Day 2: Art gallery and river walk Day 3: Market Day 4: Leave EOF git diff --check git add plan.md git rebase --continueGit replays "Pack an umbrella" without trouble and reports
Successfully rebased and updated refs/heads/extras. -
Check the result:
git log --oneline --graph --all cat plan.md packing.md git diff --check mainThe history is a straight line with your three commits on top of "Swap museum for gallery". The plan has the gallery and the river walk, the packing list has both items, and
git diff --check mainprints nothing.
Success: the rebase completed, all three changes are present, and
git diff --check is clean.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
You must edit all merge conflicts and then mark them as resolved using git add | You ran --continue before staging the file | git add <file>, then git rebase --continue |
leftover conflict marker | A marker line is still in the file | Remove it, check again, then stage |
| The rebase stops again | A later commit also conflicts | Resolve that one the same way |
no rebase in progress | The rebase already finished or was aborted | Check git log --oneline --graph --all |
| A change you wanted is missing afterwards | --skip dropped its commit | If the rebase is still running, --abort and start again; if not, see the recovery module |
-
Clean up:
cd ~/git-practice ls rm -rf rebase-conflict ls
Independent task: before cleaning up, main and extras both change the
last day:
git switch main
cat > plan.md <<'EOF'
# Trip plan
Day 1: Arrive
Day 2: Art gallery
Day 3: Market
Day 4: Leave after lunch
EOF
git commit -am "Leave after lunch"
git switch extras
cat > plan.md <<'EOF'
# Trip plan
Day 1: Arrive
Day 2: Art gallery and river walk
Day 3: Market
Day 4: Leave early
EOF
git commit -am "Leave early"
Note the ID of the newest commit on extras. Rebase extras onto main
again. This time you cannot tell which departure time is right, so stop the
rebase without changing anything, and show that extras is back on the same
commit with a clean working tree.
Check Your Understanding
- A rebase stops on a commit that adds a paragraph you still need. Would
git rebase --skipbe safe? When is skipping safe? - During a rebase, the conflict shows
<<<<<<< HEAD. Whose version follows it?
Answer and Reasoning
Independent task
git log --oneline -1
git rebase main
git status
git rebase --abort
git log --oneline -1
git status
The rebase stops on "Leave early" with a conflict in plan.md. After
git rebase --abort, git log --oneline -1 shows the same "Leave early" ID
you noted, you are still on extras, and git status reports a clean working
tree. Nothing was changed.
Understanding check
- No.
--skipdrops the whole commit, so the paragraph would be lost. Resolve the conflict and continue instead. Skipping is safe only when that commit's change is no longer needed, for example because the branch you are rebasing onto already contains the same change. - The version from the branch you are rebasing onto, together with your
commits replayed so far. Your commit's version is the one before the
>>>>>>>line, which names your commit.