Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

git checkout reports error even though working tree is clean

dbnex November 8, 2018

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 Champion
November 9, 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!

dbnex November 9, 2018

@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
TAGS
AUG Leaders

Atlassian Community Events