How to resolve conflicts during a Git rebase (Git)

Reginald LynchOctober 30th 2020, 10:05

When you rebase a commit or a branch on top of a different HEAD, you may eventually see a conflict.

If there is a conflict, you will be asked to solve the merge conflict and continue with the rebase using git rebase --continue.

Step 1 : Check out the branch named rebaseExample2, which tracks origin/stable-3.1:

git checkout -b rebaseExample2 --track origin/stable-3.1

Step 2 : Make a commit on the branch:

echo "rebaseExample2">rebaseExample.txt
git add rebaseExample.txt
git commit -m "rebaseExample2"

Step 3 : Try to rebase the branch on top of the rebaseExample branch:

git rebase rebaseExample

Step 4 : You can solve the conflict in your preferred editor. Then, add the file to the index using git add and continue with the rebase.

git add rebaseExample.txt
git rebase --continue

Step 5 : We can now check with gitk to see whether our change is rebased on top of the rebaseExample branch, as shown in the following screenshot:

gitk