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

2

12

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)?

Pukka answered 20/2, 2015 at 8:48 Comment(0)
C
12

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'.

Cleo answered 20/2, 2015 at 8:59 Comment(3)
Thanks for the tip, but it looks like merge.ff takes precedence.Pukka
@Pukka You could workaround the issue by using an alias instead of a "bare" git pull which points to git pull --ff. But please don't call it git puff.Wattle
It might appear as though merge.ff is taking precedence, but I think what's actually happening is that true isn't a valid value (the man page doesn't mention true as a possible value). The invalid value causes the option to become unset, causing fallback to the current merge.ff behavior. merge.ff doesn't seem to override pull.ff because if you set the latter to only it takes effect just fine. I'm actually somewhat annoyed that true isn't equivalent to passing --ff.Kop
K
4

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.

Kop answered 2/4, 2015 at 18:1 Comment(1)
Well spotted. +1. I have amended my own answer accordingly.Cleo

© 2022 - 2024 — McMap. All rights reserved.