Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Git-Flow: Swapping between Feature branches

Mark Cousins October 30, 2012

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

0 votes
Answer accepted
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2012

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.

Mark Cousins October 30, 2012

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?

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2012

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.

Mark Cousins October 30, 2012

Thanks. I see.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events