To proceed to push the change we just made to the remote repository, we must manually resolve the conflict. To do this, let’s execute a pull to acquire the most recent change set from the remote repository.
Execute the following git pull command.
$ git pull origin main Username: Password: remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From https://example.backlog.com/git/BLGGIT/tutorial.git * branch main -> FETCH_HEAD Auto-merging sample.txt CONFLICT (content): Merge conflict in sample.txt Automatic merge failed; fix conflicts and then commit the result.
A message will appear warning us of a merge conflict.
When you open
sample.txt, you will see markers added by Git indicating conflicts in that file section, as shown below.
Anyone can learn Git with this tutorial and Backlog add: Register a change in an index <<<<<<< HEAD commit: Save the status of an index ======= pull: Obtain the content of the remote repository >>>>>>> 17c860612953c0f9d88f313c8dfbf7d858e02e91
We are going to resolve the conflict by accepting both changes and removing the marker.
Anyone can learn Git with this tutorial and Backlog add: Register a change in an index commit: Save the status of an index pull: Obtain the content of the remote repository
Once we have resolved the conflict and the file's content has changed, we commit the changes.
$ git add sample.txt $ git commit -m "merge" [main d845b81] merge
We are now updated with the latest change from the remote repository.
We can verify the accuracy of the repository history using the git log command. The
--graph option will show the branch history in a graph format, and the
--online option will try to compact the output message.
$ git log --graph --oneline * d845b81 merge |\ | * 4c01823 append description of the pull command * | 95f15c9 append description of the commit command |/ * 3da09c1 append description of the add command * ac56e47 first commit
This indicates that the two histories successfully merged with the new merge commit. We can now safely push this change to the remote repository without any merge conflicts.