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

14,598

Solution 1

You've got a local, uncommitted .gitignore file and the changes you're trying to pull contain a tracked .gitignore file. Git is refusing to overwrite your .gitignore with the upstream one because it can't give the old one back to you later (the file is untracked).

In general, I recommend using git fetch instead of git pull. This will update your local origin/master, but not your local master. Then you can compare the tracked .gitignore in origin/master with your local .gitignore file. That's the only way to decide whether to keep one of them or merge them together.

Unfortunately, because your local .gitignore isn't tracked it's a bit tricky to automate the comparison. I recommend committing it, then using git diff master..origin/master or even just git merge origin/master. Now that your .gitignore is tracked, Git won't refuse the merge (but you may get a merge conflict that needs to be resolved).

Note that in general .gitignore should be tracked. If you have ignores that shouldn't be tracked, put them in .git/info/exclude instead.

Solution 2

Hello and welcome to Stack Overflow,

I had this problem too.. The output surprised me:

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

I've read that this happens because you have local modifications which makes merging not possible.

I've read that one of the solutions is to reset back to the head:

git reset --hard HEAD

and then pull again:

git pull

You could also consider to commit first or stash your own changes.

I am not sure, but have you already seen this question: git - strange branch merge error that I am not sure how to solve? Looks like Genadinik has the same problem.

Goodluck! I hope it helps you

Share:
14,598
bCM
Author by

bCM

Updated on June 06, 2022

Comments

  • bCM
    bCM almost 2 years

    I've been stuck with this problem for at least an hour. I'm trying to pull files with the command git pull.

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

    I tried to remove it from my local map with rm .gitignore.