9

This question and others deal with this problem in Git, but I generally work only in the SourceTree IDE. I've done some work, but before committing it, I realizes it should be on its own branch. How do I do that without losing the work I've done?

2 Answers 2

10

Just click on Branch Icon
Give Name to your branch
Click OK
Your code will automatically will sync on your new branch.
then, If you want to commit your code on that branch
just commit it on your newly created branch. (The one with BOLD)

8

It works much the same in SourceTree as in command-line Git: your unstaged, uncommitted changes aren't affected when you create and checkout a new branch.

So right-click the previous commit in the Log/history, pick "Branch..." and enter a branch name. When you "Create Branch", your unstaged uncommitted work will still be there, and you'll be in the new branch.

Stage and commit your changes as per normal.

3
  • 1
    As you say, this is standard Git behaviour. Just because the SourceTree GUI encapsulates it in a different way does not warrant it's own question. I'd argue that the duplicate you linked in OP is sufficient.
    – nbokmans
    Jan 9, 2019 at 10:23
  • 4
    @nbokmans I would pretty much agree, except that people like me use SourceTree because we don't know anything about using Git's command-line and normally search specifically for SourceTree not Git..? Open to deletion, but I would have appreciated seeing this question/answer.
    – HeyHeyJC
    Jan 9, 2019 at 14:25
  • 1
    I agree with the SourceTree angle! Also, @HeyHeyJC explained something I wasn't sure about: "your unstaged, uncommitted changes aren't affected when you create and checkout a new branch", which was helpful to me. Thank you! Apr 28, 2020 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.