As part our rebase-heavy workflow, I am hoping to use a merge on the master branch. In particular I want to merge only when the topic branch has been rebased onto the most recent master commit thereby making any merge a fast-forward one. I can achieve that by using:
git merge --ff-only
Furthermore, I would like to record the integration of the topic branch with an empty commit which is why I would like to use --no-ff which forces that behaviour:
git merge --no-ff
What I really want, though, is a combination of both: merge only when it's trivial but let me record it anyway. Git thinks that
fatal: You cannot combine --no-ff with --ff-only.
which appears self-evident to some.
git merge --edit --no-ff topicbranch
doesn't achieve the behaviour I want either. So how can I merge with the --no-ff option iff the topic branch in question is rebased to the latest master commit?
UPDATE: Seems like Charles Bailey's answer will do the trick. If you desire to have this rolled into a git alias you could issue this here:
git config --global alias.integrate '!test "$(git merge-base HEAD "$1")" = "$(git rev-parse HEAD)" && git merge --no-ff --edit $1 || echo >&2 "Not up-to-date; refusing to merge, rebase first!"'
A bit of a mouthful but works. Note the force of a commit message edit with option --edit
.