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

davet_nz August 13, 2017

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
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2017

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

davet_nz August 17, 2017

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

Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 18, 2017

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

davet_nz August 20, 2017

2.13.2.windows.1

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events