Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Merge Conflicts | Working with Branches in Git
course content

Course Content

Git Essentials

Merge ConflictsMerge Conflicts

Understanding Merge Conflicts

A merge conflict occurs when Git cannot automatically reconcile the changes made on two divergent branches. This typically happens when changes are made to the same lines of code in the same files in both branches since their last common ancestor.

Example Workflow

Let’s first list all the branches we have in our repository:

As you can see, we are currently on the master branch, so let’s modify our branch_learning.txt file by adding a new line to it and directly commit this change:

Let’s now switch to our feature branch, add a different new line to the branch_learning.txt file and directly commit this change:

Both commits are successful, so we can now switch once again to our master branch and try to merge the feature branch with it:

Oops, it seems we have encountered a merge conflict since the same line of the same file is different for each branch, and thus Git cannot automatically resolve it.

Merge conflict

Let’s also run the git status command to get more information about the conflict:

This command tells us that we have to either abort the merge or fix conflicts and commit the changes afterwards. We’ll go with the later option and resolve the conflicts in the following chapter.

Everything was clear?

Section 4. Chapter 5
course content

Course Content

Git Essentials

Merge ConflictsMerge Conflicts

Understanding Merge Conflicts

A merge conflict occurs when Git cannot automatically reconcile the changes made on two divergent branches. This typically happens when changes are made to the same lines of code in the same files in both branches since their last common ancestor.

Example Workflow

Let’s first list all the branches we have in our repository:

As you can see, we are currently on the master branch, so let’s modify our branch_learning.txt file by adding a new line to it and directly commit this change:

Let’s now switch to our feature branch, add a different new line to the branch_learning.txt file and directly commit this change:

Both commits are successful, so we can now switch once again to our master branch and try to merge the feature branch with it:

Oops, it seems we have encountered a merge conflict since the same line of the same file is different for each branch, and thus Git cannot automatically resolve it.

Merge conflict

Let’s also run the git status command to get more information about the conflict:

This command tells us that we have to either abort the merge or fix conflicts and commit the changes afterwards. We’ll go with the later option and resolve the conflicts in the following chapter.

Everything was clear?

Section 4. Chapter 5
some-alt