Home > OS >  What is/was the default git divergent merge strategy?
What is/was the default git divergent merge strategy?

Time:03-03

I recently started using a new machine and noticed and noticed this error hint when attempting to push to a branch after I resolved something online earlier on Github and forgot to pull.

So I pulled, and usually when I do this, I would get a list of the files that had changes and need to resolve them, add them, and then push.

However something different happened today when encountering this. I got this message

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.

Whenever setting up a new machine, I've never seen this before. This is my .gitconfig on two other machines that I've not seen this message on, and the one I just did:

[user]
  name = my name
  email = my email 

[format]
  numbered = auto

[color]
  branch = yes
  diff   = auto
  pager  = yes
  status = auto

I've done this many times and I suddenly have amnesia I do not recall this hint/error from git ever (6 years). Is this new? Maybe I can look at history of gits src? If not, what's the default?

CodePudding user response:

Short explanation of your issue:

Git force us to choose how it should handle out of sync between our remote branch (e.g. origin/develop) and local branch (develop), so it made it easy to modify the behavior and added this message to remind you that you might want to change the default.

To fix it we need to change the default running the following:

git pull --ff-only

or event better as a global default with

git config --global pull.ff only

CodePudding user response:

It is indeed new (partly introduced in Git 2.27, with a fix in 2.29): you can and should now configure pull.rebase and pull.ff to some setting(s).

The previous default default was the equivalent of pull.rebase false and pull.ff true. This makes git pull run git merge, doing a fast-forward non-merge "fake" merge if possible, or a real merge if not possible.

Configuring pull.ff to only makes git pull run the equivalent of git merge --ff-only as its second command (provided you're not rebasing). This is my general personal preference, but I don't have Git 2.29 or later everywhere, so I still use my own run git fetch, then poke around, then decide and maybe use my git mff alias to do a fast-forward-only merge process.

  • Related