Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

like image 518
fontno Avatar asked May 09 '13 03:05

fontno


People also ask

Does git merge fast forward by default?

By default, the git merge command is a fast-forward merge. A fast-forward merge is possible when there is a linear path from the current branch tip to the target branch.

How do you merge without fast forward?

In the event that you require a merge commit during a fast forward merge for record keeping purposes you can execute git merge with the --no-ff option. This command merges the specified branch into the current branch, but always generates a merge commit (even if it was a fast-forward merge).

What is the default git merge strategy?

Recursive is the default merge strategy when pulling or merging one branch. Additionally this can detect and handle merges involving renames, but currently cannot make use of detected copies. This is the default merge strategy when pulling or merging one branch.

What is Fast Forward in git merge?

Fast-forward merges literally move your main branch's tip forward to the end of your feature branch. This keeps all commits created in your feature branch sequential while integrating it neatly back into your main branch.


1 Answers

Set the config variable merge.ff to false:

git config --global merge.ff false 

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

like image 116
bereal Avatar answered Sep 22 '22 13:09

bereal