It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

git checkout reports error even though working tree is clean Edited

I am no my local my-feature branch

git status reports nothing to commit, working tree clean

I want to switch to develop branch and do git fetch and git merge there (I prefer it over git pull)

However, doing so produces error below

Here I first check status and it shows that all is clean

mymbp:MyProj username$ git status
On branch my-feature
nothing to commit, working tree clean

Next I try to checkout my develop branch which is an existing local branch

On branch my-feature
nothing to commit, working tree clean
mymbp:MyProj username$ git checkout develop
error: Your local changes to the following files would be overwritten by checkout:
    MyProj.sln
Please commit your changes or stash them before you switch branches.
Aborting

It complains that myProj.sln has been changed even though git status says nothing has changed.

Issuing git status again, confirms that nothing has changed

mymbp:MyProj username$ git status
On branch my-feature
nothing to commit, working tree clean

1 answer

0 votes
BillyP Community Leader Nov 09, 2018

Hi @dbnex

If you change your file in your editor and save it, it will be recognized as a change.  It isn't until the file is committed will git allow you to move on to a different branch. 

Option 1

Discard any changes in current branch.  Via the command below.  

git checkout -- . 

Next, switch to new branch and continue working

git checkout -b new-branch

Option 2

https://git-scm.com/docs/git-stash 

 

I prefer Option 1 as then I don't have a loose thing to come back and deal with later.  Extreme Coding principles being what they are :)

 

Hope this helps!

@BillyP Thanks Billy but I am not sure you understand my question.  

Option 2 makes no sense since git status, git diff, stash show that there is nothing changed, working tree is clean.  But git checkout sees this one file as changed, this is all in question above.

Option 1 makes no sense to me since all I can find about git checkout -- seem to be related to file and directory named same way, I dont have that in my case.

I posted this question and added some more updates here to clarify https://stackoverflow.com/questions/53214095/git-checkout-errors-even-though-git-status-reports-that-working-tree-is-clean

Thanks for your suggestions, 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Off-topic

Do you still play the same games you played when you were a kid?

Months ago, I was walking in a huge grocery store and I went to the toys aisle and found a jigsaw puzzle that was more than 50% off, and I thought "why not? It will be fun and it can be a beautiful f...

254 views 24 10
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you