104

I am trying to do a git pull origin master from my server but keep getting the error:

Please move or remove them before you can merge.

There are no untracked files, but it seems like it has issues with the ignored files for some reason.

I tried running a git clean -nd to see what would be deleted and it lists a whole bunch of files that are ignored in .gitignore.

How can I fix this so I can do a pull?

1

7 Answers 7

287

I just faced the same issue and solved it using the following. First clear tracked files by using :

# caution: it will **delete all untracked files**
git clean -d -f

then try git pull origin master

You can view other git clean options by typing git clean -help

Sign up to request clarification or add additional context in comments.

5 Comments

Doesn't work, I still get: error: The following untracked working tree files would be removed by merge: logs/recommend.log Please move or remove them before you can merge.
it is work . This solution should be accepted as answer.
what if i wanted to force merge incoming files in my local repo
thanks, it's working for me. I've used before reverting commit.
This answer needs to be preceded by a CAUTION. I performed this command and git deleted a lot of untracked useful files under my directory, and it was unrecoverable.
38

To remove & delete all changes git clean -d -f

1 Comment

Thanks. That worked for me. One thing to watch for: it deletes all untracked files so if you have a .env file or other local config with secrets in it, make a backup first
33

Apparently the files were added in remote repository, no matter what was the content of .gitignore file in the origin.

As the files exist in the remote repository, git has to pull them to your local work tree as well and therefore complains that the files already exist.

.gitignore is used only for scanning for the newly added files, it doesn't have anything to do with the files which were already added.

So the solution is to remove the files in your work tree and pull the latest version. Or the long-term solution is to remove the files from the repository if they were added by mistake.

A simple example to remove files from the remote branch is to

$git checkout <brachWithFiles>
$git rm -r *.extension
$git commit -m "fixin...."
$git push

Then you can try the $git merge again

7 Comments

I just added the repo to the server itself, so I went an extra step and removed it completely... then I did a git add --all on the fresh repo so it now should not be adding any ignored files. Then I committed and then did a git pull origin master but same problem still exists.
@Brett : the issue seems to exist in remote repo, not the local one. Remove the local and then pull. After that remove the files which caused the issue, commit and push. Since then the files should be ignored.
What do you mean by local? The repo on my server? The repo is in three places, local (my dev machine), bitbucket (remote) and the server - the issue I am experiencing is on the server. I don't want to psychically remove these files, just ignore them - they exist on the server, but nowhere else.
@Brett : I mean the one from which you pull the update, I.e. the bitbucket. I assume you'll do the above on your local dev repo and push the changes to bitbucket. Then you'll simply run pull on server and as the files will be removed from bitbucket repo, the issues will be gone.
Thing is, the files it is having problems with are ignored files that exist on the server only - the server has some folders that don't exist locally and hence I added them to .gitignore; so I'm not understanding why Git can't just ignore them - they aren't in the repo and are ignored.
|
7

I got this error due to the case-sensitive names of files. What I did is change the configuration of git to ignore case-sensitive by running

git config core.ignorecase true  

then tried again to pull again and it worked.

git pull

You may return the ignorecase back to false

git config core.ignorecase false   

Comments

6

If there are too many files to delete, which is actually a case for me. You can also try the following solution:

1) fetch

2) merge with a strategy. For instance this one works for me:

git.exe merge --strategy=ours master

Comments

2
git reset --hard

It actually reset all changes on your local server.

Comments

0

If you are getting error like

  • branch master -> FETCH_HEAD error: The following untracked working tree files would be overwritten by merge: src/dj/abc.html Please move or remove them before you merge. Aborting

Try removing the above file manually(Careful). Git will merge this file from master branch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.