Can't do a git pull

Git

Git Problem Overview


I'm trying to do a git pull and get the error message:

error: The following untracked working tree files would be overwritten by merge:
<myFileName>
Please move or remove them before you can merge.

So, I try to remove the file using the command git rm --cache which results in the error:

fatal: pathspec
<myFileName>
did not match any files

At this point I'm stuck. I can't pull until I remove the file. But, it tells me I can't remove the file.

What can I do to fix this?

Git Solutions


Solution 1 - Git

This is an opportunity for the 'git clean' command. If you don't care about the untracked files ... git clean -n to see what will be removed, and git clean -f to go ahead and rm untracked files.

Add -d to the commands to also operate on directories:

  git clean -dn
  git clean -df

Solution 2 - Git

You have untracked files in the way of the pull. You can't remove them with git rm --cached because they are untracked. They don't appear in the index. You need to remove them with plain old rm

Solution 3 - Git

That file isn't in the current branch yet, so you can't remove it with git rm --cache. Just use rm.

Solution 4 - Git

I agree with other posters, the issue is that the file isn't being tracked by git. the command git rm works on files being tracked. rm will remove the file from your machine. Alternatively you could add the file to your list of ignored files, or file types if that is convenient. You could also use one of the GUI tools like tortoise git to quickly delete all untracked files.

Solution 5 - Git

As it says in the original error message, that file is untracked. That means git doesn't know anything about it. Just remove it from the filesystem using rm. If you care about the contents, just move it somewhere else.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionToddView Question on Stackoverflow
Solution 1 - GittroyfolgerView Answer on Stackoverflow
Solution 2 - GitWolfView Answer on Stackoverflow
Solution 3 - GitEdward DaleView Answer on Stackoverflow
Solution 4 - GitXylaraxView Answer on Stackoverflow
Solution 5 - GitCarl NorumView Answer on Stackoverflow