Cyberithub

Solved "fatal: Need to specify how to reconcile divergent branches"

Advertisements

In this article, we will look into how to solve "fatal: Need to specify how to reconcile divergent branches" error. Last night while working on my project, I tried to pull changes from a remote branch using git pull command but instead I end up with error "fatal: Need to specify how to reconcile divergent branches". This prevented me to proceed further hence before solving this problem I decided to write an article about this so that it will help you folks as well. Check Atlassian Git tutorial to know more about the merge strategy.

Solved "fatal: Need to specify how to reconcile divergent branches"

Solved "fatal: Need to specify how to reconcile divergent branches"

Also Read: How to Delete a Branch in Git Using 2 Easy Methods

If you are working on Git system then it is not very uncommon to get this error while trying to perform git pull from your remote repository. While most of the time you will see "fatal: Need to specify how to reconcile divergent branches" as a warning but sometimes you will get it as a fatal error. If the error is showing as warning then you would still be able to pull the changes from repo but if it is showing as fatal error then you would not be allowed to proceed further.

cyberithub@ubuntu:~$ git pull origin main
From https://cyberithub.com/bitbucket/scm/repo/example-repo
*branch dev -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

Hence to overcome this error, you can try below two solution and apply whichever works for you. But even before that please check your current git version by using git --version command. Below solution found to be working fine on Git 2.27.0 and onwards.

cyberithub@ubuntu:~$ git --version
git version 2.35.1

 

Solution 1: Switch to Merge Strategy

When there are remote changes that are not on your local branch, they need to be resolved. The default Git behavior is merging, which will create a new commit on your local branch that resolve those changes. You can use git config pull.rebase false command to switch back to default merging strategy instead of using rebasing strategy.

cyberithub@ubuntu:~$ git config pull.rebase false

After switching back to default strategy, you can again try running git pull origin main command to pull all the changes from main branch. This time you can see that all the changes are now merged by the 'ort' strategy. Check here to know more about ort strategy.

cyberithub@ubuntu:~$ git pull origin main
From https://cyberithub.com/bitbucket/scm/repo/example-repo
*branch dev -> FETCH_HEAD
Merge made by the 'ort' strategy.
application.yaml | 13 ++++++++++++
config.yaml | 160 ++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++
2 files changed, 173 insertions(+)
create mode 100644 application.yaml
create mode 100644 config.yaml

 

Solution 2: Switch to fast-forward Strategy

Sometimes your default strategy would be FF only. So to switch back to this strategy, you need to run git config --global pull.ff only command as shown below.

Advertisements
cyberithub@ubuntu:~$ git config --global pull.ff only

This will add below line to $HOME/.gitconfig:-

[pull] 
      ff = only

But it is also important to note here that Git will update your branch only if it can be “fast-forwarded” without creating new commits. If this can't be done meaning if local and remote have diverged, then git config --global pull.ff only simply aborts with an error message.

Hopefully above solution will help you solving this error. If it still doesn't then probably it requires some more In-depth analysis. Please let me know your feedback on the comment box.

Leave a Comment