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.
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.
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.
It's not possible to have conflicting changes in a fast-forward merge.
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.
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
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