Brett
Brett

Reputation: 20049

Git pull - Please move or remove them before you can merge

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?

Upvotes: 102

Views: 309101

Answers (7)

Neha
Neha

Reputation: 3650

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

Upvotes: 282

Uchchwas Das
Uchchwas Das

Reputation: 11

git reset --hard

It actually reset all changes on your local server.

Upvotes: 1

Amr Omar
Amr Omar

Reputation: 557

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   

Upvotes: 7

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

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

Upvotes: 33

David
David

Reputation: 157

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

Upvotes: 5

DURGESH
DURGESH

Reputation: 2453

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

Upvotes: 38

Deepak G
Deepak G

Reputation: 733

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.

Upvotes: 0

Related Questions