Sub topic 6
Resolving conflicts: --continue, --skip, and --abort
This chapter assumes you can run git add, git commit, and git log. It also assumes you know how to rebase a branch onto origin/main. Here you will learn what to do when a rebase stops on a conflict.
Why a rebase stops
Rebase replays your commits one at a time on top of the new base. If a commit changes lines that the new base also changed, Git cannot decide which version to keep. It stops, reports a conflict, and waits for you.
While stopped, the rebase is in progress. Git is applying one commit, and the rest are queued. git status shows which commit is being applied and which files conflict.
Resolve and continue
Fix each conflicted file, stage it, and continue.
git rebase origin/main
# CONFLICT reported: edit the conflicted files, then
git add path/to/file
git rebase --continueInside a conflicted file, Git marks the two sides:
<<<<<<< HEAD
timeout = 30
=======
timeout = 60
>>>>>>> a1b2c3d (Raise request timeout)During a rebase, the top section (HEAD) is the code from the new base plus the commits already replayed. The bottom section is the commit being applied now. This is the reverse of what many people expect. Edit the file so it contains the result you want, and delete all three marker lines.
After git rebase --continue, Git creates the commit and moves to the next one. The next commit may conflict too, so expect to repeat the loop.
Skip a commit
git rebase --skip drops the commit currently being applied and moves on. Use it when the new base already contains the same change, for example because someone else landed an equivalent fix. Skipping discards that commit's work from your branch, so check with git show first.
Abort
git rebase --abort stops the rebase and restores the branch to its state before you started.
git rebase --abortUse it when the conflicts are bigger than expected or you are unsure of your edits. It is safe, and you can try again later.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| `git rebase --continue` says there are unmerged paths | A conflicted file was not staged | Run `git add` on each file listed by `git status` |
| Markers like `<<<<<<<` appear in committed code | You staged the file without removing the markers | Search for `<<<<<<<`, fix, and amend or continue |
| "No changes" and the rebase will not continue | Your resolution made the commit empty | Run `git rebase --skip` |
| Ours and theirs seem swapped | Rebase reverses the usual meaning | Remember the base side is `HEAD`, your commit is the other |
Exercise
During a rebase, a commit conflicts, and you decide the new base already contains an identical fix, so your commit is redundant. Which command do you run, and how does it differ from --abort?
Show answer
Run git rebase --skip. It discards only the current commit and continues replaying the rest. git rebase --abort cancels the entire rebase and returns the branch to its state before it started.
Exercise
After editing a conflicted file, git rebase --continue reports unmerged paths. What did you forget?
Show answer
You did not stage the resolved file. Run git add on it, then git rebase --continue.