I typically work with (meaningfully named) feature branches in git.
F1---F2--- feature-xyz / M1---M2---------- master
If I now merge the feature branch into the master, and in the meantime no further changes have been commited to the master, then by default the information is lost that I have worked on a feature branch.
M1---M2---F1---F2--- master
The reason for this is the fast-forward mode of git (see also https://ariya.io/2013/09/fast-forward-git-merge). Especially if several changes were commited to the feature branch, I would like to see them separately on a branch:
F1---F2 / \ M1---M2--------MC--- master
This can be achieved by using the --no-ff
(i.e. no fast-forward) parameter for the merge process
(also see https://git-scm.com/docs/git-merge).
git merge --no-ff feature-xyz
Using --no-ff creates another commit - the Merge Commit (MC ) - which is omitted in the fast-forward mode.
|
Change the default behaviour of git
If you want to use the no fast-forward mode by default, there are several possibilities (also see https://stackoverflow.com/questions/2500296/can-i-make-fast-forwarding-be-off-by-default-in-git):
Enable --no-ff
only for the master
If you want to use the no fast-forward mod only for the master branch then execute the following command in your git project:
git config branch.master.mergeoptions "--no-ff"
This will add the following lines to the file .git/config
[branch "master"]
mergeoptions = --no-ff
Additionally using the parameter --global
will change the setting for all projects on your machine.
The configuration is modified in the case in the file ~/.gitconfig
.
Keep in mind that the option
will change the global configuration,
will change to configuration of the repository. |
Enable --no-ff
for all branches
If you want to use the no fast-forward mode for all branches of your repository, then execute the following command in your project folder:
git config --add merge.ff false
This will add the following lines to the file .git/config
:
[merge]
ff = false
Additionally using the parameter --global
will change the setting for all projects on your machine.
The configuration is modified in the case in the file ~/.gitconfig
.