Try:

git mergetool

It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.


As per Josh Glover's comment:

[This command] doesn't necessarily open a GUI unless you install one. Running git mergetool for me resulted in vimdiff being used. You can install one of the following tools to use it instead: meld, opendiff, kdiff3, tkdiff, xxdiff, tortoisemerge, gvimdiff, diffuse, ecmerge, p4merge, araxis, vimdiff, emerge.


Below is a sample procedure using vimdiff to resolve merge conflicts, based on this link.

  1. Run the following commands in your terminal

    git config merge.tool vimdiff
    git config merge.conflictstyle diff3
    git config mergetool.prompt false
    

    This will set vimdiff as the default merge tool.

  2. Run the following command in your terminal

    git mergetool
    
  3. You will see a vimdiff display in the following format:

      ╔═══════╦══════╦════════╗
      β•‘       β•‘      β•‘        β•‘
      β•‘ LOCAL β•‘ BASE β•‘ REMOTE β•‘
      β•‘       β•‘      β•‘        β•‘
      ╠═══════╩══════╩════════╣
      β•‘                       β•‘
      β•‘        MERGED         β•‘
      β•‘                       β•‘
      β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
    

    These 4 views are

    • LOCAL: this is the file from the current branch
    • BASE: the common ancestor, how this file looked before both changes
    • REMOTE: the file you are merging into your branch
    • MERGED: the merge result; this is what gets saved in the merge commit and used in the future

    You can navigate among these views using ctrl+w. You can directly reach the MERGED view using ctrl+w followed by j.

    More information about vimdiff navigation is here and here.

  4. You can edit the MERGED view like this:

    • If you want to get changes from REMOTE

      :diffg RE
      
    • If you want to get changes from BASE

      :diffg BA
      
    • If you want to get changes from LOCAL

      :diffg LO
      
  5. Save, Exit, Commit, and Clean up

    :wqa save and exit from vi

    git commit -m "message"

    git clean Remove extra files (e.g. *.orig). Warning: It will remove all untracked files, if you won't pass any arguments.

Answer from Peter Burns on Stack Overflow
Top answer
1 of 16
3457

Try:

git mergetool

It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.


As per Josh Glover's comment:

[This command] doesn't necessarily open a GUI unless you install one. Running git mergetool for me resulted in vimdiff being used. You can install one of the following tools to use it instead: meld, opendiff, kdiff3, tkdiff, xxdiff, tortoisemerge, gvimdiff, diffuse, ecmerge, p4merge, araxis, vimdiff, emerge.


Below is a sample procedure using vimdiff to resolve merge conflicts, based on this link.

  1. Run the following commands in your terminal

    git config merge.tool vimdiff
    git config merge.conflictstyle diff3
    git config mergetool.prompt false
    

    This will set vimdiff as the default merge tool.

  2. Run the following command in your terminal

    git mergetool
    
  3. You will see a vimdiff display in the following format:

      ╔═══════╦══════╦════════╗
      β•‘       β•‘      β•‘        β•‘
      β•‘ LOCAL β•‘ BASE β•‘ REMOTE β•‘
      β•‘       β•‘      β•‘        β•‘
      ╠═══════╩══════╩════════╣
      β•‘                       β•‘
      β•‘        MERGED         β•‘
      β•‘                       β•‘
      β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
    

    These 4 views are

    • LOCAL: this is the file from the current branch
    • BASE: the common ancestor, how this file looked before both changes
    • REMOTE: the file you are merging into your branch
    • MERGED: the merge result; this is what gets saved in the merge commit and used in the future

    You can navigate among these views using ctrl+w. You can directly reach the MERGED view using ctrl+w followed by j.

    More information about vimdiff navigation is here and here.

  4. You can edit the MERGED view like this:

    • If you want to get changes from REMOTE

      :diffg RE
      
    • If you want to get changes from BASE

      :diffg BA
      
    • If you want to get changes from LOCAL

      :diffg LO
      
  5. Save, Exit, Commit, and Clean up

    :wqa save and exit from vi

    git commit -m "message"

    git clean Remove extra files (e.g. *.orig). Warning: It will remove all untracked files, if you won't pass any arguments.

2 of 16
1808

Here's a probable use case, from the top:

You're going to pull some changes, but oops, you're not up to date:

git fetch origin
git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.

So you get up-to-date and try again, but have a conflict:

git add filename.c
git commit -m "made some wild and crazy changes"
git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.

So you decide to take a look at the changes:

git mergetool

Oh my, oh my, upstream changed some things, but just to use my changes...no...their changes...

git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"

And then we try a final time

git pull origin master

From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Ta-da!

🌐
Atlassian
atlassian.com β€Ί git β€Ί tutorials β€Ί using branches β€Ί merge conflicts
How to Resolve Merge Conflicts in Git? | Atlassian Git Tutorial
When this happens, it is not because of conflicts with other developer's, but conflicts with pending local changes. The local state will need to be stabilized using git stash, git checkout, git commit or git reset. A merge failure on start will ...
Discussions

Need help understanding a merge conflict. I don't think there is one, so I am definitely not understanding something.

You are trying to merge in a commit that makes a change to a file that has been deleted in the working tree

More on reddit.com
🌐 r/git
9
5
March 9, 2019
git bash - Git says "Automatic merge failed", what does it mean? - Stack Overflow
I tried to merge two branches and this is what i did and what happened: Abdulla (Master) new-git-project1 $ git merge sidebar Auto-merging index.html CONFLICT (content): Merge conflict in index.html More on stackoverflow.com
🌐 stackoverflow.com
Git merge conflict problem - Automatic merge failed; fix conflicts and then commit the result - Stack Overflow
How can resolve this merge conflict? Automatic merge failed; fix conflicts and then commit the result. I get this for several files e.g below, but it has some modifications only (see below) file c... More on stackoverflow.com
🌐 stackoverflow.com
What happens after I resolve a merge conflict on my feature branch?
In step 5, doing the "accept yours" says that your version is the 100% correct one. It is possible that this is correct, it is possible that this is wrong. It is possible that this was just some whitespace that both of you changed, but its also possible that this was a bug fix that now represents a regression. When dealing with a merge conflict, you should review the change that is coming in to see what is correct. It is possible that neither are and you'll need to make some other changes to get the merge correct. In step 7, your team lead shouldn't see a merge conflict on merging the changes in. From the dev branch perspective, your file can trace its ancestry back to the version of the file that is currently on the dev branch - that's what the merge does. The biggest risk comes from that you did an 'accept yours' rather than reconciling the changes. Something changed on dev that you overwrote in your feature branch when you did 'accept yours'. More on reddit.com
🌐 r/git
7
5
September 26, 2022
🌐
Atlassian Support
support.atlassian.com β€Ί atlassian support β€Ί bitbucket β€Ί resources β€Ί set up and work on repositories in bitbucket cloud β€Ί use pull requests for code review
Resolve merge conflicts | Bitbucket Cloud | Atlassian Support
May 14, 2020 - Resolving deltas: 100% (137/137), completed with 2 local objects. From bitbucket.org:tutorials/tutorials.git.bitbucket.org * branch HEAD -> FETCH_HEAD Auto-merging editme.html CONFLICT (content): Merge conflict in editme.html Automatic merge failed; fix conflicts and then commit the result.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί git β€Ί merge-conflicts-and-how-to-handle-them
Handling Merge Conflicts in Git - GeeksforGeeks
March 30, 2026 - CONFLICT (content): Merge conflict in <fileName> Automatic merge failed; fix conflicts and then commit the result.
🌐
OneUptime
oneuptime.com β€Ί home β€Ί blog β€Ί how to fix 'merge conflict' errors in git
How to Fix 'Merge Conflict' Errors in Git
January 24, 2026 - Rebase conflicts can require resolving the same conflict multiple times as each commit is replayed. # During rebase, conflict occurs git rebase main # Resolve the conflict # Edit files, remove markers # Continue with the rebase git add src/config.js git rebase --continue # If the same conflict appears again # Git rerere can help (described below) Rerere (reuse recorded resolution) remembers how you resolved conflicts and applies the same resolution automatically in the future.
🌐
DataCamp
datacamp.com β€Ί tutorial β€Ί how-to-resolve-merge-conflicts-in-git-tutorial
How to Resolve Merge Conflicts in Git Tutorial | DataCamp
March 15, 2025 - To stabilize the local state, you ... branch where multiple developers have modified the same file. If the automatic merge fails, Git will ask you to resolve issues manually....
🌐
Opensource.com
opensource.com β€Ί article β€Ί 20 β€Ί 4 β€Ί git-merge-conflict
How to resolve a git merge conflict | Opensource.com
April 22, 2020 - Make your edits as necessary, then close the file: This is a new README file This is an edit on the branch Β· As you can see, this keeps the branch's edits. You can run git status to see further instructions: $ vim README.md $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add ..." to mark resolution) both modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
Find elsewhere
🌐
Reddit
reddit.com β€Ί r/git β€Ί need help understanding a merge conflict. i don't think there is one, so i am definitely not understanding something.
r/git on Reddit: Need help understanding a merge conflict. I don't think there is one, so I am definitely not understanding something.
March 9, 2019 -

I have a github project I'm working with 4 others for a school project. I have a branch conflict, but I'm unsure why.

I own the primary repo. The other 4 members have forked the project to their own. I've added .vs and obj directories to .gitignore and ensured they're not in the project. They're gone.

One of the party members submitted a huge chunk of code as a pull request that has those files. Fine, whatever... I can work with him later to get those files removed from the repo. In the short term, another group member needs his changes.

Conflicting files
.vs/jatar-core/v15/.suo
jatar-core/obj/jatar-core.csproj.nuget.cache
jatar-core/obj/jatar-core.csproj.nuget.g.props

How can those files be conflicting if they do not exist in the primary project?

Edit: Full merge conflict text is below when attempting to cludge my way through a command line conflict resolution:

remote: Enumerating objects: 25, done.
remote: Counting objects: 100% (25/25), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 13 (delta 7), reused 13 (delta 7), pack-reused 0
Unpacking objects: 100% (13/13), done.
From github.com:adamatic7/jatar
 * branch            master     -> FETCH_HEAD
CONFLICT (modify/delete): jatar-core/obj/jatar-core.csproj.nuget.g.props deleted in HEAD and modified in 91955ab679c8516e653f1eca6c1df0b2689cff3f. Version 91955ab679c8516e653f1eca6c1df0b2689cff3f of jatar-core/obj/jatar-core.csproj.nuget.g.props left in tree.
CONFLICT (modify/delete): jatar-core/obj/jatar-core.csproj.nuget.cache deleted in HEAD and modified in 91955ab679c8516e653f1eca6c1df0b2689cff3f. Version 91955ab679c8516e653f1eca6c1df0b2689cff3f of jatar-core/obj/jatar-core.csproj.nuget.cache left in tree.
CONFLICT (modify/delete): .vs/jatar-core/v15/.suo deleted in HEAD and modified in 91955ab679c8516e653f1eca6c1df0b2689cff3f. Version 91955ab679c8516e653f1eca6c1df0b2689cff3f of .vs/jatar-core/v15/.suo left in tree.
Automatic merge failed; fix conflicts and then commit the result.
🌐
GitHowTo
githowto.com β€Ί resolving_conflicts
25. Resolving conflicts
Let us rerun the merge. ... To resolve the conflict, we need to edit the file to the state we're happy with and then commit it as usual. In our case, we will combine the changes from both branches.
🌐
Sentry
sentry.io β€Ί sentry answers β€Ί git β€Ί resolve merge conflicts in git
Resolve merge conflicts in Git | Sentry
March 15, 2023 - Whether we’ve resolved conflicts ... automatically stages the changes for merged files, so we just need to create a new commit (git commit -m "Merge resolution")....
🌐
GitHub
docs.github.com β€Ί articles β€Ί resolving-a-merge-conflict-using-the-command-line
Resolving a merge conflict using the command line - GitHub Docs
> # (fix conflicts and run "git commit") > # > # Unmerged paths: > # (use "git add <file>..." to mark resolution) > # > # both modified: styleguide.md > # > no changes added to commit (use "git add" and/or "git commit -a") Open your preferred text editor, such as Visual Studio Code, and navigate to the file that has merge conflicts. Search the file for the conflict marker <<<<<<<. The changes from the HEAD or base branch appear after <<<<<<< HEAD, followed by =======, then the changes from the other branch and >>>>>>> BRANCH-NAME.
🌐
Linode
linode.com β€Ί docs β€Ί guides β€Ί resolving-git-merge-conflicts
How to Resolve Merge Conflicts in Git | Linode Docs
October 22, 2021 - Remember to commit or stash any uncommitted changes in your working directory, since git reset --hard wipes away any local changes that have not been committed. When you’re done resolving your conflicts, use git add to mark the files you’ve resolved. Then, use git merge --continue to complete the process.
🌐
LinksysInfo.org
linksysinfo.org β€Ί forums
Build Question ["Automatic merge failed; fix conflicts and ...
March 4, 2023 - Discussion board of 3rd Party firmwares for ASUS, Linksys, Netgear, and other WiFi Routers.
🌐
Nulab
nulab.com β€Ί learn β€Ί software-development β€Ί git-tutorial β€Ί how-to-use-git β€Ί branching β€Ί resolve-merge-conflict
Resolve a merge conflict | Git tutorial | Nulab
Once the conflict is resolved, commit the change. $ git add myfile.txt $ git commit -m "merge issue3 branch" # On branch main nothing to commit (working directory clean) ... You can see that a new merge commit has been created as a result of the conflict resolution.
Top answer
1 of 2
22

You have encountered a merge conflict. It means that Git cannot automatically determine how to merge the two branches. Git is asking you to do the merge manually, and gives you some help along the way by telling you what files it cannot automatically merge, and what changes specifically in these files that it has trouble with.

Run git status. It will output a list of what files are unmerged. These files will contain conflict markers that look similar to this:

foo

<<<<<<< HEAD
BAR
=======
bar baz
>>>>>>> foo

qux

This means that HEAD (or, the commit or branch you are currently on) has changed a line to BAR, and the branch foo has changed the same line to bar baz.

Edit each of these conflicts to your liking, making sure that you have no more conflict markers left. For example, if you preferred the BAR version in the above example, you would simply edit the file so that it looked like:

foo

BAR

qux

Save each file and add it as you go.

# (edit <file>)
git add <file>

There are tools available that do the file editing part for you, some find them easier to use than to edit the files manually.

When you are done, run git status to make sure that you have no more unmerged files. Then, run git commit to finish the merge if you are happy with the result.

Git - Basic Branching and Merging provides some more information about merge conflicts.


A different and often* saner way to go about this is to first rebase the other branch (in this case sidebar) on top of the branch you are merging it into (in this case master):

git checkout sidebar
git rebase master

You will likely still have conflicts, but fixing them here is sometimes easier. The procedure is the same as described above, edit the files, add them, commit. When done, run git rebase --continue to continue the rebase procedure.

Then, finally you can merge the branch with no conflicts:

git checkout master
git merge --no-ff sidebar

The --no-ff is optional; with it you will get a merge commit to denote that you merged a branch, without it your history will be linear with no merge commit.

A benefit of rebasing before merging is that there will never be merge conflicts in the actual merge, meaning that the merge commit never introduces a change other than what is already introduced by the commits in the branch being merged. This makes the history easier to understand.

A downside to rebasing is that commits are applied on top of a new state of the code. This has the implication that you need to check each commit to see that it still does the right thing. It is a good idea to spend a little time doing this in order to avoid future surprises.

* Avoid or at least use caution when rebasing branches that have merges. Rebase eats merges. It is also a good idea to avoid rebasing another person's commits. The author of a change is usually the person who knows best how to properly resolve any merge conflicts caused, so if possible, conflict resolution is best delegated.

2 of 2
1

This message means that there are some changes in index.html on both the branches which are not identical. So there are merge conflicts. So you have to resolve these conflicts using a mergetool like meld. Here you have to decide which changes you have to keep on this branch. After resolving these conflicts you have to commit your local changes and then push it to remote git repository. You can refer below link for resolving the conflicts. https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/

🌐
Nushackers
wiki.nushackers.org β€Ί orbital β€Ί git β€Ί fundamental-concepts β€Ί merge-conflicts
Merge Conflicts | NUS Hackers Wiki
(fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: hello.txt no changes added to commit (use "git add" and/or "git commit -a") ... On ...
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 63645643 β€Ί git-merge-conflict-problem-automatic-merge-failed-fix-conflicts-and-then-comm
Git merge conflict problem - Automatic merge failed; fix conflicts and then commit the result - Stack Overflow
I don't know what merge tool you are using, nor why it's showing the merged file as all-question-marks, but the conflict is clear enough: one side changed two lines (deleting two module names), the other side deleted one line and changed one line (to remove a comma and one module name).
🌐
Medium
gkzz.medium.com β€Ί git-troubleshooting-6344c35724e8
Git Troubleshooting. Automatic merge failed; fix conflicts… | by gkzz | Medium
March 23, 2019 - $ git add lists/templates/home.html $ git commit -m β€œmanage.py test passed” lists/templates/home.html $ git branch chapter1 chapter2-feature-unittest chapter2-feature-unittest-exception chapter3-testing-simple-hp-with-unittests * chapter4-refactoring chapter4-refactoring-from-No00973 chapter4-refactoring-from-No01175 chapter4-refactoring-from-No01278 chapter5-saving-user-input chapter5-saving-user-input-from-No01491 chapter5-saving-user-input-from-No01526 master $ git push origin chapter4-refactoring $ git checkout chapter5-saving-user-input $ git merge chapter4-refactoring Auto-merging lists/templates/home.html CONFLICT (content): Merge conflict in lists/templates/home.html Automatic merge failed; fix conflicts and then commit the result.
🌐
Kbroman
kbroman.org β€Ί github_tutorial β€Ί pages β€Ί merge_conflicts.html
Handling merge conflicts
Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.
🌐
Git-is-my-lab-book
git-is-my-lab-book.net β€Ί guides β€Ί using-git β€Ί how-to-resolve-merge-conflicts
How to resolve merge conflicts? - Git is my lab book
In addition to showing "our" changes and "their changes", this three-way diff also shows the original lines, between the ||||||| and ======= markers. This extra information can help you decide how to best resolve the conflict. We can edit test.txt to reconcile these changes, and the commit our fix.