Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off fast-forward merging for regular merge, but not for pull

I want git to always make merge commits (--no-ff) when I use git merge, but keep the default behavior (--ff) for git pull. Is this possible (with configs)?

like image 749
oyvind Avatar asked Feb 20 '15 08:02

oyvind


2 Answers

The two configs which might help are:

merge.ff

(From git merge man page): When set to false, this variable tells Git to create an extra merge commit in such a case (equivalent to giving the --no-ff option from the command line).

pull.ff

(from the git config man page)

Setting pull.ff to true would keep the default behavior where Git does not create an extra merge commit when merging a commit that is a descendant of the current commit.

To be tested: does pull.ff takes precedence over merge.ff?

git config pull.ff only
git config merge.ff false

As mentioned by Kelvin's answer and confirmed by git-pull.sh, 'only' is the value to use, not 'true'.

like image 187
VonC Avatar answered Nov 04 '22 21:11

VonC


Here's my tentative workflow (Note that the pull.ff config option only works on git 2.x.).

Use this config:

  • Set merge.ff to false. This defaults the merge behavior to --no-ff.
  • Set pull.ff to only. This defaults the pull behavior to --ff-only.

That means if you try to pull a branch where your local is both behind & ahead of the remote, the pull will fail. In that case, do a rebase so you're not behind any more.

Note:

I tried setting pull.ff to true but git seems to treat it as though the option is entirely unset. Note that the man page doesn't mention that true is a recognized value.

like image 35
Kelvin Avatar answered Nov 04 '22 19:11

Kelvin