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?

HeyHeyJC
  • 2,627
  • 1
  • 18
  • 27

2 Answers2

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)

H45H
  • 1,019
  • 10
  • 28
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.

HeyHeyJC
  • 2,627
  • 1
  • 18
  • 27
  • 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 09 '19 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 09 '19 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! – Francois Bertrand Apr 28 '20 at 13:15