Reputation: 1069
I am not sure how I got my local git repo into its current state, but when I am on master and I try to checkout another branch, I get the following error:
error: The following untracked working tree files would be overwritten by checkout:
src/path/to/Checklist/filename.ext
(I've obfuscated the actual path and filename). The problem is with the "Checklist" folder. In the repo, and in my local file path this folder is named "CheckList" (notice the capital L).
I've tried the following commands, but none of them resolve the problem:
git reset --hard HEAD
(no error output, but doesn't resolve the problem)
git reset --hard origin/master
(no error output, but doesn't resolve the problem)
git rm src/path/to/Checklist/filename.ext
"fatal: pathspec 'src/path/to/Checklist/filename.ext' did not match any files"
git add -A && git stash
"No local changes to save"
I've also tried deleting the "CheckList" folder followed by a reset --hard. And I have tried renaming the folder to "CheckList2" then to "Checklist", then either deleting it or not followed by reset --hard. None of these combinations have resolved the problem either.
I am able to use the "-f" option to check out the other branch, but any time I go back to master, the problem returns.
Note that browsing the master branch in GitLab there is no folder called "Checklist" (only the correctly named one called "CheckList"). So it does not appear to be an issue where there are two folders in the repo with the same name in different cases.
-- EDIT --
So you don't have to read through the comments on the accepted answer, the specific solution to my problem was to look at the other branch(es) that I was trying to check out. The "Checklist" folder doesn't exist in 'master' branch or in my local path. Instead, those other branches have both a "CheckList" and "Checklist" folder in them. Since this is a Windows file system, that isn't allowed. The error message is just misleading.
Upvotes: 3
Views: 1234
Reputation: 522506
error: The following untracked working tree files would be overwritten by checkout:
I believe this error is occuring because the file in question is untracked in the master
branch, but in the branch to which you are trying to switch there is an actual tracked file in that exact location. Switching branches would mean clobbering the currently untracked file, and Git is alerting you to this.
I've tried the following commands, but none of them resolve the problem:
git reset --hard HEAD
...
The problem is with an untracked file, which is not managed by Git, so it therefore should come as no surprise that Git commands have no effect.
To remedy this, you can simply delete this file, then do the checkout. If you really need this file in master
, then add it to Git.
Upvotes: 0