HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

How can I disable Git's fast forward merging by default?

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
defaulthowmergingdisableforwardgitcanfast

Problem

Git's default behavior is to fast forward when merging branches. This means that if the branch you're merging into hasn't diverged from the branch you're merging, Git will simply move the pointer to the new commit. This is known as a fast-forward merge.
However, there are cases where you might want to disable fast-forward merging by default. For example, you might want to preserve the history of the branches you're merging, or you might want to enforce a merge commit to capture the merge operation.
In order to disable the default fast-forward merging behavior in Git, you can use the merge.ff configuration option. By using git config --add merge.ff false, you can disable fast-forward merging for all branches, even if it is possible. You can also use the --global flag to configure this option globally.

Solution

# Usage: git config [--global] --add merge.ff false

git config --global --add merge.ff false
# Globally disables fast-forward merging by default

git checkout master
git merge my-branch
# Will never fast forward even if it's possible


In order to disable the default fast-forward merging behavior in Git, you can use the merge.ff configuration option. By using git config --add merge.ff false, you can disable fast-forward merging for all branches, even if it is possible. You can also use the --global flag to configure this option globally.

Code Snippets

# Usage: git config [--global] --add merge.ff false

git config --global --add merge.ff false
# Globally disables fast-forward merging by default

git checkout master
git merge my-branch
# Will never fast forward even if it's possible

Context

From 30-seconds-of-code: disable-fast-forward

Revisions (0)

No revisions yet.