Company policy is to use --no-ff
for merge commits. I personally like to adjust merge log messages so I use --no-commit
. Plus I like to actually compile and test before I let the commit go.
How do I make --no-ff
and --no-commit
the default for me for all branches?
(and I've learned in the years since asking this, I almost always am happy with the commit, so it is simpler to allow it to commit by default and so long as I amend or otherwise fix things up before doing a push things are all good...)
Using the --no-ff parameter prevents the Git merge command from performing a fast-forward merge when Git detects that the current HEAD is an ancestor of the commit that you're trying to merge.
The --no-ff flag prevents git merge from executing a "fast-forward" if it detects that your current HEAD is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit.
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.
How Git Pull –ff-only Works. Fortunately, Git gives us an option that prevents the accidental creation of new shas in your repository. With git pull --ff-only , Git will update your branch only if it can be “fast-forwarded” without creating new commits.
Put this in $HOME/.gitconfig:
[merge] ff = no commit = no
You can use git-config to do this:
git config --global merge.commit no git config --global merge.ff no
To make --no-ff --no-commit
the default merge behavior, set the options to no
using:
git config --global merge.ff no git config --global merge.commit no
However, the problem with this is that git pull
= git fetch
+ git merge
. So whenever you pull from the remote server, you'd be creating an ugly merge commit when a simple fast-forward would be warranted. To solve this, set pull.ff
to yes
:
git config --global pull.ff yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With