How to Finish a Merge After Resolving Conflicts in Git

John Wachira Feb 02, 2024
How to Finish a Merge After Resolving Conflicts in Git

This article outlines the process of completing a merge after resolving the merge conflicts in Git. We will go through the merging steps, resolve conflicts and finish the merge.

Finish a Merge After Resolving Conflicts in Git

For easier context, we will simulate a scenario where merging two branches in our repository results in conflict. Here is the typical workflow.

Switch to our main branch and make some edits to the README.md file.

$ git checkout main

After making edits, we will commit the file, switch to our Dev2.1 branch and make changes to the README.md file.

$ git checkout Dev2.1

We will edit the same lines for Git to create a merge conflict. After committing, we can now run the git merge command.

$ git merge main

Output:

git merge main

To resolve merge conflicts, we highly recommend using a mergetool like Meld. We already have Meld configured as our default diff and mergetool.

To launch it, we will run:

$ git mergetool

After resolving the conflicts, we can quickly check the state of our working tree and index.

$ git status

Output:

git status

As suggested by Git, we can run the git commit command to finish the merge process. In our case, we will run:

$ git commit -m "Merge Dev2.1 to main"

Output:

[Dev2.1 cb9b842] Merge Dev2.1 to main

An alternative way of finishing a merge is using the git merge --continue command. The command will prompt us to a text editor where we are supposed to give our commit a name to finish the merge.

$ git merge --continue

If we do not want to edit the commit message, we can run:

$ git merge --continue --no-edit

Output:

git merge –continue –no-edit

In a nutshell, we can complete a merge after resolving conflicts using Git’s suggested command, git commit or git merge --continue command. Both will give the same desired output.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Merge