50

I am trying to pull changes from remote branch but getting an error which doesn't make sense

when I do

git pull

I get back

error: Your local changes to the following files would be overwritten by merge:
file/name/path
some/more/filenamepath
Please, commit your changes or stash them before you can merge.
Aborting

Problem is I have no changes that need to be committed When I do git status

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 7 different commits each, respectively.
#
nothing to commit (working directory clean)

there are no working changes

I've tried git reset --hard HEAD but that didn't help

any ideas?

Files are on the NFS file system, maybe that has something to do with. This is on OSX

Thanks


UPDATE: This issue has to do something with NFS, because when I went to the original source and did git pull from there everything worked fine, which fixed it for this instance, but still not sure exactly why it causes issues with NFS.

darkgaro
  • 567
  • 1
  • 6
  • 9
  • 1
    Have you tried leaving out HEAD in your git reset --hard? Give that a try first. – Dylan Corriveau Aug 31 '14 at 23:36
  • @DylanCorriveau `HEAD` is actually the default. – musiKk Sep 01 '14 at 07:23
  • Can you clone the repo onto your system's hard disk and do your work there? Then you could bypass the NFS issue entirely.... – Yawar Sep 02 '14 at 23:46
  • 1
    I'm guessing it has to do with line endings: CRLF vs LF. I'm using NFS on a NTFS filesystem and this issue popped up. – DWils Oct 27 '16 at 00:05
  • Related post - [How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?](https://stackoverflow.com/q/14318234/465053) – RBT May 09 '19 at 08:29
  • `git checkout path/to/file` using the path to the problematic file, then `git pull` – Stack Sep 18 '20 at 14:29

5 Answers5

46
  1. Delete the problematic files.
  2. Run git reset --hard.

That should fix it.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Dan
  • 1,805
  • 2
  • 18
  • 21
32

I had this same issue, and the fetch/rebase answer didn't work for me. Here's how I solved it:

I deleted the file that was causing the issue, checked it out, and then pulled successfully.

  1. rm file/name/path/some/more/filenamepath
  2. git checkout file/name/path/some/more/filenamepath
  3. git pull
pferg
  • 678
  • 7
  • 10
9

You should:

  • fetch (updating all remote tracking branches, like origin/master)
  • rebase your current branch on top of origin/master in order to replay your 2 commits on top of the 7 updated commits that you just fetched.

That would be:

git checkout master
git fetch
git rebase origin/master

A shorter version of the above set of commands would be the following single command:

git pull --rebase
Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    That didn't work, I get ```Cannot rebase: You have unstaged changes. Please commit or stash them.``` But there is actually no unstaged changes – darkgaro Sep 02 '14 at 21:05
  • First of all, you need to merge the previous file, for example if README.md file needs to be merge you should execute the following command: -git merge README.md -git add README.md After the end of the process you should run -git commit -m "Add comment" -git push – Panos Angelopoulos Mar 06 '15 at 11:42
2

Had the same issue. Solved it by re-cloning the repo. But now I think that the reason was the line endings in these files. I played with them before.

I suppose that line-ending difference doesn't mark files as changed, but may lead to this message. When you rm the files and recheckout them, line endings should set to "good state", and pull goes fine.

Andrey Regentov
  • 3,687
  • 4
  • 34
  • 40
1

I had the same problem but with the .idea / vcs.xml and workspace.xml files. I deleted the 2 files then used the command: - git pull "remote" "brench"

Mihai Vlasceanu
  • 161
  • 1
  • 2