Git-Flow: Swapping between Feature branches

Hi

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.

Thanks

1 answer

1 accepted

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

672 views 0 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