Resolve a conflict
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.
Right-click on the “tutorial” directory and select “Pull”.
Click “OK.”
If you see an info box teaching you about merges, read it and click “OK”.
When you see the warning message that the automatic merge has failed, click “Close”.
You will then be asked if you would like to see the changes in this revision. Click “Yes”.
TortoiseGit is telling us that the automatic merge has failed because “sample.txt” has a merge conflict. Click “OK”.
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 will need to initiate a commit.
Right-click and choose Git Commit -> ‘main.’
A window about merges will display; click “OK”.
Right-click the sample file and choose “Resolved,” since we just resolved this merge conflict manually using our text editor.
When a window displays to confirm this change, click “Yes.”
When warned about the commit message still mentioning the conflicting files, choose “Ignore” or “Abort.” Then remove the lines from the commit message or follow the advice at the bottom to have TortoiseGit automatically remove lines starting with a “#” for you. (Automatically removing these is the default behavior for most other Git clients.)
We are now updated with the latest change from the remote repository.
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.
If you don’t want to learn to use Git on Mac or Command Line next, head straight to the branching section.