9

When I git pull origin development, I got error:

error: Untracked working tree file '<path-to-file>' would be overwritten by merge

The reason is because one file which is in the remote development branch is not put to git in my local project (I don't want that file in version control, so did git rm). But on remote development, that file is exit for version control

How to resolve this problem? Basically, I want the remote branch also remove the file from version control.

Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • 1
    Possibly duplicate of http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull – vpatil Feb 14 '12 at 10:49

4 Answers4

5

To resolve your immediate problem, you should make a backup of the local file, remove the original, pull from the remote branch, and then git rm (followed by a push, to make sure the remote repo deletes the file as well). Then you can put the backup file back locally, and add a line to your .gitignore file.

Peter Bratton
  • 6,302
  • 6
  • 39
  • 61
  • The problem happens when git pull. – Leem.fin Feb 15 '12 at 10:22
  • 1
    I'll edit my answer. What you need to do is remove the local untracked copy. What's happening is that a file exists remotely, but not locally. git will not allow you to overwrite a local untracked file. – Peter Bratton Feb 16 '12 at 22:42
2

This is happening due to an untracked file will be overwritten by a new file coming in from the pull request

My suggestion would be to:

git add .
git stash
git pull

Basically adding the files that aren't tracked into your git repo and stashing them away and pulling in the new version.

dannio
  • 900
  • 8
  • 12
0

As @vpatil linked, and I found on this somewhat related git issue, @mtkumar82 over there suggest doing the following:

git fetch --all
git reset --hard origin/{{your branch name}}

This worked perfectly for me, since I had untracked files that were of no importance to the code itself, so they were untracked, and I did not care what version they were. I hope this helps people in the future that end in this thread and not the other, bigger one, as it happened to me (in fact google did not show even this one, I found it once I already had the solution).

monkey intern
  • 705
  • 3
  • 14
  • 34
-1

You can use gitignore option.
For details refere these -

http://help.github.com/ignore-files/
http://linux.die.net/man/5/gitignore

vpatil
  • 3,380
  • 1
  • 17
  • 9
  • .gitignore won't help here. That's not the OP's problem: (s)he has previously added a file, so adding it to .gitignore won't help. – Edward Newell May 15 '14 at 23:58