gitgit-merge

How to set no "fast forward" as default when using git merge


From the git book:

You’ll notice the phrase "Fast forward" in that merge. Because the commit pointed to by the branch you merged in was directly upstream of the commit you’re on, Git moves the pointer forward. To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together — this is called a "fast forward".

However, the side effect of this "fast forward" is that if you have a feature branch with multiple commits you will lose the historical context of the feature when you merge back into master. In other words, the commits wont be grouped together as part of this feature.

with fast forward:     x---x---x---x---x---x---x

without fast forward:  x---x---x         x---x---x---x
                                \x--x--x/

The manual way is to git merge --no-ff

Does anyone know how to set this as a default?


Solution

  • Set the config variable merge.ff to false:

    git config --global merge.ff false
    

    (Without --global to limit the effect to the current project)