10

When I am trying to pull from git,getting below error

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

I have tried to stash changes but after stash pull is not working, asking for merge.

How can I pull changes without commiting/adding existing?

Maroun
  • 94,125
  • 30
  • 188
  • 241
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
  • 1
    Force it, use the `-f` flag (you'll loose your local changes). `git stash` *should* work, how are you using it? – Maroun Apr 30 '15 at 12:04
  • I hope this answer will help you to solve your problem. http://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files/41929861#41929861 – Faisal Jan 30 '17 at 06:21
  • Does this answer your question? [Why does git say "Pull is not possible because you have unmerged files"?](https://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files) – Flimm Jan 03 '22 at 12:37

6 Answers6

12

First backup the conflicted files!


Then execute:

git fetch origin
git reset --hard origin/master (or your branch name)

This way you should get the full git repository code if you want restore conflict file or compare them.

Alex Gyoshev
  • 11,929
  • 4
  • 44
  • 74
D.Y.
  • 149
  • 2
  • 7
9

Isn't it because you have an ongoing merge? Have you done

$ git merge --abort 

This will cancel the merge that was ongoing. After that, you should be able to pull. The pull might induce a new merge if some conflicts are found. Be aware that the "merge abort" will cancel any modification made in the context of the merge.

iclman
  • 1,218
  • 9
  • 21
  • I dont want to remove changes from local when trying to pull data.means if same file is changed from local and server, it will merged and generate conflicts when pull thats what i want. So, Will it work for this? or it will ignore files needs merge? – Bhumi Shah May 13 '15 at 05:53
3

To preserve your changes as well , Commit or stash your changes first, there are some files which have conflicts. Install kdiff3 as a merge tool from the following link

When you do a git pull now, the console will show changes, type git mergetool -y and merge the changes manually.

SJMan
  • 1,547
  • 2
  • 14
  • 37
1

I'm not sure what you want to do, but if its pulling and removing your changes, then git reset is what you need to do.

See: http://git-scm.com/docs/git-reset

What you want is probably

git reset --hard

Be warned, this will remove any changes you made to your files!

Afterwards, the pull should work.

Boelensman1
  • 314
  • 2
  • 15
  • I dont want to remove changes from local when trying to pull data.means if same file is changed from local and server, it will merged and generate conflicts when pull thats what i want. – Bhumi Shah May 13 '15 at 05:52
0

You can get around this by checking out a new branch and committing your changes there. Then you can force update the main branch from your remote as intended, and work on merging the code locally. But this is why doing new work in its own branch is ideal.

Matt
  • 2,982
  • 1
  • 22
  • 23
-1

Try with below Command:

git fetch origin
git reset --hard origin/master
git pull
Faisal
  • 4,591
  • 3
  • 40
  • 49