Managing Conflicts When Rebasing

What happens if the rebase operation runs into conflicts? Let's take a look.

We'll cover the following

In the previous lesson, we discussed what rebasing does and also tested out a scenario where we were able to carry out and observe a successful rebase operation.

However, it’s not all that simple.

Why conflicts can occur when rebasing

What if you decided to rebase your branch with the latest version of the parent branch, which contains new commits that have changed the same files at the same location within those files where you have also included your changes?

Do note that when a rebase is carried out, it takes place commit by commit. Therefore, what would happen if one of the parent branch’s commit conflicted with the changes one of your branch’s commit was trying to introduce? Git is not intelligent enough to decipher which changes to keep and which ones ought to be discarded.

That’s where it will prompt the rebase not to be completed and will require you to handle the conflict by picking out the changes you want to keep and discarding the rest. Once you are done with that, you can choose to continue the rebase operation that had been paused. You can also choose to completely abort the rebase operation altogether if such a situation arises. You might realize that a large number of conflicts could occur with each new commit that is applied, making it troublesome to resolve every conflict.

Let’s test this scenario out using the terminal provided below. Here is what has happened for now:

Get hands-on with 1200+ tech skills courses.