Search code examples
gitgit-mergegit-pullgit-clean

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?


Solution

  • 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