Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with git branch checkout due to untracked working tree files

I thought I put the days of Xcode + git issues behind me. Guess not. I am getting this git error when trying to checkout another branch.

error: The following untracked working tree files would be overwritten by checkout:
    RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
    RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme
    RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist
Please move or remove them before you can switch branches.
Aborting

Very well I say, let me remove these files:

andrewjl$ git rm --cached RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
fatal: pathspec 'RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate' did not match any files

At this point I'm not sure what to do. These files are all listed in my .gitignore and I also gave git clean -f -d a try as well. No dice. Anyone know what's going on here?

like image 678
Andrew Lauer Barinov Avatar asked Dec 08 '12 23:12

Andrew Lauer Barinov


People also ask

How do you solve error the following untracked working tree files would be overwritten by checkout?

In this article, we looked at two ways to correct an working tree file error that would be overwritten on checkout. Most times, we can do exactly what the git error says to correct it. In this instance, we can either commit the changes or stash the changes to clear the working tree so we can change branches.

Does git checkout affect untracked files?

git checkout does not affect untracked files. Git only manages tracked files, and it works fairly hard to avoid letting you lose data (which is critical).

Can I switch branch with untracked files?

Normally when you switch branches the untracked files are brought along with you without any notice. That's why they're called "untracked". However, you say that the untracked files would be overwritten. This implies that you have created an untracked file in the new branch which already exists in the master branch.


3 Answers

The files are untracked: git rm --cached cannot find them because there are not in the index. Just delete them, using your file manager or rm. Then checkout should work as expected. Note that git status will show you what git sees the files as (tracked, changed, untracked; with an additional option it will also display ignored files).

like image 127
Nevik Rehnel Avatar answered Oct 04 '22 02:10

Nevik Rehnel


they arent in git but there locally .. that means when you switch those would be lost and git doesnt allow that

remove them locally:

rm RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist

they are recreated by xcode anyway. nothing important in there!

like image 32
Daij-Djan Avatar answered Oct 04 '22 02:10

Daij-Djan


Try this

git rm --cache */xcschemes/xcschememanagement.plist

git commit -m "Good bye xcschememanagement.plist"

like image 34
Sreeraj VR Avatar answered Oct 04 '22 01:10

Sreeraj VR