Anouar Asmai
Anouar Asmai

Reputation: 43

Why the conflicts are always with merging branches?

I'm learning the concepts of Git, I was testing some commands to understand how Git works.

I created a remote repository on my Github and cloned it.

To test merging between branches ran command:

git checkout -b add_Bob

This line was to create my new branch. Then changed my Bob.txt file, then committed the changes :

git checkout master

However, I changed the same line on the same file on the master branch. I then merged the "add_Bob" branch to my "master branch" :

git merge add_Bob

It showed a conflict on the Bob.txt file like this :

Auto-merging Bob.txt
CONFLICT (content): Merge conflict in Bob.txt
Automatic merge failed; fix conflicts and then commit the result.

Why these conflicts are showing ?

Upvotes: 0

Views: 537

Answers (1)

Hamza Belmellouki
Hamza Belmellouki

Reputation: 2718

Merge conflicts happen because you've modified the same line(s) in your branches.

To fix it open Bob.txt your favorite editor and search for these characters: <<<<<<< HEAD. ======= divides your changes from the branches which is followed by >>>>>>> name of the branch

If you want to keep only your branch's changes remove the markers and make the appropriate modification.

After resolving merge conflicts stage and commit your changes.

git add .
git commit -m "commit message" 

Upvotes: 1

Related Questions