Git pull fails with a warning about reconciling divergent branches
Platform Notice: Cloud, Server, and Data Center - This article applies equally to all platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When you try to pull a repository, you are met with an error like -
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
Cause
This warning was added in Git 2.27. Git makes it mandatory to define the default behavior for reconciliation of branches when merging in git config. Hence, when there is no default method defined, this warning is shown until we define a default behavior.
Solution
There are a few ways we can resolve this error depending on the version of git you use. All the solutions boil down to defining a default behavior for git pull with respect to reconciliation of branches.
As the warning says, the most straight-forward method is to define one of the following entries in git config -
- pull.rebase false
- pull.rebase true
- pull.ff only
All mechanisms will still try to use fast forward merge if it is possible. Else, it will fall back to the configured merge strategy.
If you want to make a merge commit when branches have diverged, you can type the following (Use the global parameter if you want to define the same behavior for all repositories instead of doing it per repository) -
git config pull.rebase false
OR
git config --global pull.rebase false
If you want to perform a rebase by default, use the below commands -
git config pull.rebase true
OR
git config --global pull.rebase true
If you want git to reject the pull if a fast forward option is not available, type the following -
git config pull.ff only
OR
git config --global pull.ff only
Git version 2.29 or above
There is a second way to define the above solutions if your git version is 2.29 or above. You can check your git version with the following command -
git -v
If you want to attempt a fast forward if possible and if not, make a merge commit, enter the following -
git config pull.ff true
OR
git config --global pull.ff true
If you never want to make a fast forward and always merge, you can use the below command -
git config pull.ff false
OR
git config --global pull.ff false
If you only want to do a fast forward and never do a merge or rebase (reject the commit if fast forward is not available) -
git config pull.ff only
OR
git config --global pull.ff only