Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull error: Your local changes to the following files would be overwritten by merge:

Tags:

git

bitbucket

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.

like image 917
darkgaro Avatar asked Aug 31 '14 23:08

darkgaro


People also ask

Will a git pull overwrite my changes?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

How do I force git pull to overwrite local files?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

Can't pull commit changes before merging?

The “commit your changes or stash them before you can merge” error is raised when you try to pull code from a remote repository that conflicts with a local change you have made to a repository. To solve this error, either commit your change to the repository, discard your change, or stash your change for later.


5 Answers

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

That should fix it.

like image 161
Dan Avatar answered Sep 30 '22 10:09

Dan


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
like image 29
pferg Avatar answered Sep 28 '22 10:09

pferg


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
like image 41
VonC Avatar answered Sep 28 '22 10:09

VonC


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.

like image 34
Andrey Regentov Avatar answered Oct 01 '22 10:10

Andrey Regentov


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"

like image 34
Mihai Vlasceanu Avatar answered Sep 29 '22 10:09

Mihai Vlasceanu