Git-Flow: Swapping between Feature branches


I'm quite new to Git and Sourcetree (so may be being stupid here...let me know if I am) and have been using Sourcetree successfully with differing branches and remerging etc.

If I switch a branch using 'normal Git/Sourcetree'), I need to stash my changes before leaving my current branch. This is good (for me) for (say) two different feature developments. I've now introduced Git Flow and like the concept that it introduces. However, I notice that if I have several Feature branches in development and switch between them, my changes are not stashed and the mods are reflected across each branch, even into the develop branch if I switch to that.

Am I missing something here? I want to be able to switch between different Feature branches and the develop branch and have separate 'source codes' without all modifications being shared across all branches. Is this correct? It seems a bit confusing.

Help and advice appreciated.


1 answer

1 accepted

0 votes
Accepted answer

SourceTree never actually stashes your changes for you, it tries to keep them as you switch branches unless you say otherwise. This is because sometimes you might start developing something, and then realise you're currently on the wrong branch so want to switch over to do the commit.

If you prefer to stash, you should click the Stash button on the toolbar before switching branches. Or alternatively, you could commit locally and not push the changes - you can always amend the commit before pushing next time. Whichever you're most comfortable with.

Thanks, that's helped. My query then is why does Git insist on Stashing when switching 'normal' branches, but not when switching Git Flow branches?

It actually depends on the realtionship between the branches - if there's a direct ancestor for both of them then the switch can occur without stashing.

Thanks. I see.

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...

1,123 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