floatingpurr
floatingpurr

Reputation: 8599

Git: files persist while switching between two branch

I have two branches: master and web and I have my working copy in one directory. In web branch I've the folder foo. I worked on foo's files and I committed the job. Then I switched to master with:

git checkout master

But foo folder is still there in my working copy. It looks strange! Git status on master branch tells me the all is fine. But the folder foo does not belong to master branch. Even If I do

git checkout .

web folder stays in my working copy. To fix I rm web folder. Now, git status keeps telling me the everything is fine and so it is.

But it's very strange, what could have happened and how can I avoid that?

Upvotes: 3

Views: 2086

Answers (1)

Harald Nordgren
Harald Nordgren

Reputation: 12409

I think you have a file in foo that is commited to master as well. Compare the output of

git checkout web
git ls-files foo

with

git checkout master
git ls-files foo

The ls-files command should return empty if the folder is not versioned. But I think you will get output anyway.

Git does keep track of which folders are exclusive to a branch and will remove them when switching branches. git status also reports on all untracked files that are not in the .gitignore.

Upvotes: 1

Related Questions