Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force merge commit and fast forward in git-merge [duplicate]

Tags:

git

git-merge

Is it possible to merge only fast-forwardable branches and create a merge commit? I want to rebase the branches before merging but still have the branch separately in history. So, I'm wondering if there is some way to make sure that git won't merge if the branch hasn't been rebased (--ff-only) but at the same time create a merge commit (--no-ff). Giving both --ff-only and --no-ff doesn't work.

Motivation: I want to have linear history but so that each feature branch is clearly separate. They just follow one after another.

like image 632
Jaakko Luttinen Avatar asked May 06 '16 10:05

Jaakko Luttinen


People also ask

How do I fast forward in git merge?

Rebasing to perform a fast-forward merge on GitRebasing can be used to create a merge fast forward on Git thanks to its ability to make both the master branch and your feature branch's history (besides the new feature branch changes) identical.

What is the difference between fast forward merge and 3 way merge of branches?

It is called so because, in the 3-way merge, Git uses three commits to generate the merge commit; two branch tips and their common ancestor. Typically, the fast forward merge is used by developers for small features or bug fixes while the 3-way merge is reserved for integrating longer-running features.

Is it possible for a fast forward merge to have conflicts?

It's not possible to have conflicting changes in a fast-forward merge.

How do you merge without fast forward?

In order to do that, you can pass the --no-ff flag and git merge will always construct a merge instead of fast-forwarding. Similarly, if you want to execute a git pull or use git merge in order to explicitly fast-forward, and you want to bail out if it can't fast-forward, then you can use the --ff-only flag.


1 Answers

git config alias.mff '!mff() { git merge --ff-only "$1" && git reset --hard HEAD@{1} && git merge --no-ff "$1"; }; mff'

and from then on

git mff other-branch
like image 164
Vampire Avatar answered Sep 18 '22 12:09

Vampire