Sourcetree merge branch into master automatically commits - why?

Sometimes when I merge a branch into master the files automatically commit themselves ready for a push. Typically I would expect a merge to first appear in the Working Copy area so I can review which files I do actually want to commit or remove.

Am I performing the merge incorrectly? While I'm in the Master branch I right-click on the branch to merge in then click "Merge branch into master".

Confusingly this problem only happens some of the time. On occasion the files do appear in the Working Copy area as expected.

Any suggestions welcome!

1 answer

1 accepted

2 votes
Accepted answer

This happens because it is the way Git is designed to operate. The occasions when the files do NOT automatically commit are almost always because there is a conflict that needs resolved before you can commit.

There is good news, though. The fact that the merge is committed does not, in any way, prevent you from reviewing and modifying the changes. Review the diffs in the commit details, make any changes you need to make. Then, when you commit, select "amend previous commit".

Ok, thanks that makes sense. One other question though - when it auto-commits it doesn't give me a chance to add a log message. For example, if I merge from branchA into master I'd like to add "Merge 'branchA' into Master". Instead what actually happens is it uses the last commit message from that branch.

From what you've suggest it sounds like I could do an "amend previous commit" and add the message there, but it seems like an extra unneccessary step, especially if I don't have any further actual file amendments?

Hope this makes sense .. ?

That does makes sense, but doesn't match the behavior of SourceTree on my machine. When I merge, the automatically-generated commit message is something like "Merge branch 'branchA' into master".

You might try a command line merge and see what commit message it uses.

@Seth  this is also happening on my side its not creating merge commit that is "Merge branch 'branchA' into master"

When the merge comfirmation dialog opens, there is an option to "Create a new commit even if a fast forward is possible" - try that.

What is probably happening is that no changes were made to master between when you created your branch and when you merged it back. In that scenario, there isn't actually anything to merge, so by default git will instead "fast-forward" the master branch to the last commit on branchA. The option I mentioned will force git to create a new commit anyway (which is often preferred when dealing with a "master" or "dev" branch).

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

972 views 4 2
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