Let's say you have cloned a repository and there are two branches, main and feature/development and you are on the feature/development branch.
~]# git branch --all
* feature/development
main
remotes/origin/HEAD -> origin/main
remotes/origin/feature/development
remotes/origin/main
And you issue the git pull command and there are merge conflicts. Notice that each of these merge conflict have a different reason:
- modify/delete
- content
- add/add
~]$ git pull origin main
From ssh://git.example.com/myrepo
* branch main -> FETCH_HEAD
CONFLICT (modify/delete): example.yml deleted in HEAD and modified in a0d52bf8805449e35907acd6f9979f015b5a7f4a. Version a0d52bf8805449e35907acd6f9979f015b5a7f4a of example.yml left in tree.
Auto-merging foo.yml
CONFLICT (content): Merge conflict in foo.yml
Auto-merging bar.yml
CONFLICT (add/add): Merge conflict in bar.yml
Automatic merge failed; fix conflicts and then commit the result.
For the files that have conflict "modify/delete" this means the file may have been modified in the main branch and deleted in the feature branch. If the file is no longer needed, it can simply be deleted in the main branch.
For the files that have conflict "content", which is foo.yml in this example, the file should have something like this. This is basically trying to show you the conflict between the file in the feature branch vs. origin.
~]$ cat foo.yml
<<<<<<< HEAD
hello
=======
world
>>>>>>> a0d52bf8805449e35907acd6f9979f015b5a7f4a
One way to fix this is to update the files to be identical in the feature and main branch. It almost always makes sense to update the file in the feature branch. You may need to create a new commit with the -i flag which is used to stage the commit.
git commit -i -m "resolved merge conflict" foo.yml
Be aware that if there are 2 or more files, you may need to do the staged commit for all files together.
git commit -i -m "resolved merge conflict" foo.yml bar.yml
And then try the git pull origin main command again.
git pull origin main
And git push origin HEAD.
git push origin HEAD
Did you find this article helpful?
If so, consider buying me a coffee over at 