Checkout new branch doesn't discard changes

In some branch I made some changes, but didn't add them to the index. 

Next I checked out a new branch to track a remote one and saw that the changes made while working on the first branch where still there. I would have expected them being discarded because now the local branch doesn't reflect the state of the remote branch.

Ok, but the problem is SourceTree has no option in de Checkout New Branch tab to discard/cleanup changes.


1 answer

Git won't discard uncommitted files unless you explicitly tell it to. If the files that you changed are identical between the two branches (besides the uncommitted changes), Git will allow you to switch while keeping the changes (useful if you realized you were making the changes on the wrong branch, or just created a new branch for changes you were creating).

New files will always be kept as well, and Git should only complain if you try to check out a branch that has an indexed file with the same name/location.

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,110 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