git flow merge --no-ff

Hi all,

For what I've learn about git-flow, when someone finish a feature (or a hotfix, is the same), git flow should be merge the feature branch into develop (and also into master in case of hotfix branch) using --no-ff options.

Using git-flow with SourceTree (all version, Windows and Mac), this does not happen.

When I click on "finish feature" (for example) the next window show me a checkbox with "rebase on development branch" label, that seems a choise for what SourceTree have to do: as shows the preview panel on the bottom of the window, seems that leaving it unchecked SourceTree will do a merge with --no-ff flag, but this doesn't happen.

SourceTree always does what git does naturally: a fast forward merge if there aren't commit in develop branch from the creation of the branch, a no fast forward merge in the other case.

I've tried also to activate the option "do no fast forward when merging, always create commit" under "git option", but also in this case seems that nothing changes: every time, if there aren't commit between branch creation and branch merging, SourceTree does a fast forward merge.

So, there is a way to solve this? I'd like to implement exactly git-flow workflow...

Thanks!

3 answers

1 accepted

0 votes
Accepted answer

This is actually what standard git-flow does - if there are no commits on the develop branch since the feature was started, it does not use the --no-ff option. SourceTree is just calling the git-flow script and this has been its behaviour for a long time.

A few people have expressed that they don't like this, and I think at least one person has forked git-flow to change this behaviour, so far we've stuck to the stock version. This is the code in the git-flow scripts that makes the choice:

if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then
		git merge --ff "$BRANCH"
	else
		git merge --no-ff "$BRANCH"
	fi

The problem with this standard Git-flow behavior is that the Feature-branch name in the merge message is lost. With 2+ commits in a feature branch the merge message would look like "Merge branch 'feature/CRE-128' into develop". Opposed to that, a single commit feature-branch, which is merged with fast-forward only contains the commit message, which dont has the Feature/JIRA-issue attached to it. Any plans on customizing this behavior? Or the best workaround? Is it save to alter the git-flow scripts or are they overwritten with the next update?

Ok, for everyone encountering the same issue like the Lorenzo (as myself). SourceTree (win) uses the original GitFlow script, but extract them to folder "%UserHome%\AppData\Local\Atlassian\SourceTree\gitflow_local\gitflow\". So, to always merge with no-fast-forward (especially for single-commit-features), in file "git-flow-feature", replace the following...

# merge into BASE
	git checkout "$DEVELOP_BRANCH"
	if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then
		git merge --ff "$BRANCH"
	else
		git merge --no-ff "$BRANCH"
	fi

with this...

# merge into BASE
	git checkout "$DEVELOP_BRANCH"
	git merge --no-ff "$BRANCH"

 

which I think is the expected and cleaner behavior. Would be really grateful if this would be added to SourceTree.

So git flow never do a --no-ff merge if into the feature branch there is only a commit? I've well understand the code?

Thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 01, 2018 in Summit

Summit 2019 is going to Las Vegas

You asked we answered - Summit 2019 registration is now open! Can you believe Atlassian Summit hasn’t been to the US since 2017? Now is the time to get ready for an event to remember! Our biggest u...

283 views 6 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you