Reputation: 198867
I can't really ever think of a time when I would use git merge
rather than git rebase
and not want to have a commit show up. Is there any way to configure Git to have fast forwarding off by default?
The fact that there's an --ff
option would seem to imply that there's a way, but I can't seem to find it in the documentation.
Upvotes: 306
Views: 117449
Reputation: 605
git config --replace-all pull.ff false
The above command worked for me to remove fast forward merge from all branches
Upvotes: 4
Reputation: 1192
Reading the thread of answers, I ended up using the following two options:
# Disallows non ff merges on pull. Overrides merge.ff when pulling
git config --global pull.ff only
# Even create extra merge commit when fast forward merge would be possible
git config --global merge.ff false
Only loosely related, I've also found this setting avoids trouble during pull:
# Set up pull to rebase instead of merge
git config --global pull.rebase true
Upvotes: 34
Reputation: 383
These answers didn't work for me until I applied the config not only on global:
git config --global pull.ff only
git config pull.ff only
in local my pull.ff config was false
(instead of only
)
Upvotes: 0
Reputation: 10152
It seems there is still a pending question in the thread: How to do it globally (i.e. for all branches) ? For the records, we can use the following:
git config --add merge.ff false
...to make it apply to all branches in the current repository. To make it apply to all branches in all repositories where someone has not run it without the --global
option (local settings override global) run this:
git config --global --add merge.ff false
From the documentation:
merge.ff
By default, git does not create an extra merge commit when merging a commit that is a descendant of the current commit. Instead, the tip of the current branch is fast-forwarded. 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). When set to only, only such fast-forward merges are allowed (equivalent to giving the--ff-only
option from the command line).
Upvotes: 377
Reputation: 10151
Yes, there is --no-ff
. You can configure merge options per branch, e.g.
git config branch.master.mergeoptions "--no-ff"
adds the following to your $(REPO)/.git/config
file:
[branch "master"]
mergeoptions = --no-ff
Footnote: speaking of my experience, I eventually found switching fast-forward to off was mostly helpful for git newcomers - however once the feel for workflows and concepts start to sink in you definitely want to avoid blurring your log graph with tons of pointless 'merged remote ..blarf' type commits.
Footnote 2, a decade later: the other answers below provide more modern config options, but really, you probably DO want to stay with the defaults (i.e. fast-forward whenever possible) in this day and age, because empty merge-commits really only make the history much more difficult to reason about.
Upvotes: 304