Git Foundations / Rebase Unpublished Work

Resolve conflicts during a rebase

Lesson 21 of 33. Open to read. No account needed.

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:

  • <<<<<<< HEAD introduces 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 with git 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.

  1. 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
    
  2. Rebase extras onto main:

    git rebase main
    

    The first commit replays cleanly. Then Git reports CONFLICT (content): Merge conflict in plan.md and could not apply for "Add river walk".

  3. 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.md is both modified.

  4. Read the conflict:

    cat plan.md
    
    <<<<<<< HEAD
    Day 2: Art gallery
    =======
    Day 2: Museum and river walk
    >>>>>>> 8f44b56 (Add river walk)
    

    The HEAD side is main's new version; the other side is your commit.

  5. Both changes are wanted: the gallery from main and 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 --continue
    

    Git replays "Pack an umbrella" without trouble and reports Successfully rebased and updated refs/heads/extras.

  6. Check the result:

    git log --oneline --graph --all
    cat plan.md packing.md
    git diff --check main
    

    The 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 main prints nothing.

Success: the rebase completed, all three changes are present, and git diff --check is clean.

If something differs:

What you seeLikely causeNext step
You must edit all merge conflicts and then mark them as resolved using git addYou ran --continue before staging the filegit add <file>, then git rebase --continue
leftover conflict markerA marker line is still in the fileRemove it, check again, then stage
The rebase stops againA later commit also conflictsResolve that one the same way
no rebase in progressThe rebase already finished or was abortedCheck git log --oneline --graph --all
A change you wanted is missing afterwards--skip dropped its commitIf the rebase is still running, --abort and start again; if not, see the recovery module
  1. 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

  1. A rebase stops on a commit that adds a paragraph you still need. Would git rebase --skip be safe? When is skipping safe?
  2. 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

  1. No. --skip drops 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.
  2. 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.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy