Why does Sourcetree allow switching of branches with uncomitted changes. The "git checkout" doesn't

Sourcetree Version 2.1.2.5

I make changes in a branch, and forget to commit them (am new to git so haven't gotten into the habit).

I then use Source tree to switch to the next branch, which it quite hapily does.

I then find the code is exactly what it was with the other, uncommitted changes. Very confusing.

I then switched to the command line and tried a "git checkout" to the other repository and git wouldn't let me do it, saying there are uncommitted changes.

Why does Sourcetree allow it?

 

Dave

1 answer

0 votes

Hi Dave, I'm not sure I understand the problem you describe. I've tried to reproduce it using Git in the terminal and I've been able to switch to different branches even if I didn't commit my changes. Here's what I did:

  1. Created "branch 1" from master.
  2. Made some changes in this branch and didn't commit them.
  3. Switched to an existing "branch 2" successfully.
  4. Made some changes in this branch and didn't commit them.
  5. Created new "branch 3" and switched to it successfully.

Are those the steps you followed? If you're still having issues, can you clarify a bit more?

Best regards,

Ana

Hi Ana,

That is exactly the problem.

Sourcetree allows you to switch branches without committing your changes.  Git does not.  If at step 3 you try using command line git commands to checkout branch 2, it will not let you.

the git command and it's output is

C:\a_check>git checkout 02926D-A_add_comments_only
error: Your local changes to the following files would be overwritten by checkout:
db_objects/emp_change.pls
Please commit your changes or stash them before you switch branches.
Aborting

Sourcetree allows the checkout to 02926D thus confusing you over what changes are actually in the directory.

I did notice that if the changes are from a conflicted merge, Sourcetree will not allow the switch.

 

Dave

Hi Dave, that's weird, for my previous example I used only the command line git, I was not using SourceTree. Which git version are you using? I have git version 2.11.0 (Apple Git-81).

Regards,

Ana

2.13.2.windows.1

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

2,387 views 9 12
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