Search code examples
gitmergebranchrebasefast-forward

Can I make fast forwarding be off by default in Git?


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.


Solution

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