27

I'm working with a developer here who is seeing a weird issue that I've never encountered before. He's working on a repository and needs to pull the latest changes from someone else before he can push. All of his changes are committed.

$ git pull
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

Which seems reasonable enough until...

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 3 and 1 different commit each, respectively.
#
nothing to commit (working directory clean)

Say what?

I've tried git reset --hard HEAD before pulling, but the pull still fails.

Only one guy is seeing this and he's on a Mac (OSX 10.6.8). Any ideas? I'm about to pull my hair out.

Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192
  • What value do you get if you run `git config branch.autosetuprebase`? If it is set to `always` that might explain what is happening here. – ThomasW Apr 04 '13 at 08:22

6 Answers6

26

Instead of

git pull

try

git fetch
git rebase -p origin/master

If that doesn't work you can try

git pull --no-rebase

How to check why this message occurs

Make sure you on a branch, not a detached head. Rebasing doesn't work on a detached head.

Run the following commands, the result should be no output.

git update-index -q --ignore-submodules --refresh
git diff-files --ignore-submodules
git diff-index --cached --ignore-submodules HEAD --
Peter van der Does
  • 14,018
  • 4
  • 38
  • 42
9

Are you working on local filesystem or nfs share?

I had exactly the same problem when I was working on nfs share.

I have added noatime option to the mount command and it helped:

mount -t nfs -o noatime,... device dir
Tomasz
  • 91
  • 1
  • 2
1

for me issue was with files in secure folder

  1. only this command has shown that there are files unstaged

    git diff-files --ignore-submodules
    
  2. de-configure git-crypt and re-encrypt files in work tree

    git-crypt lock
    
srghma
  • 4,770
  • 2
  • 38
  • 54
0

You can try for $ git stash then try for git pull.

Raje
  • 3,285
  • 15
  • 50
  • 70
0

I had this issue when I tried to rebase a repo owned by root (and I was an unprivileged user).

Chris Beach
  • 4,302
  • 2
  • 31
  • 50
-1

Looks like there might be a rebase in progress. Try running git rebase --abort first.

More forceful methods to clean out the local include

  • Delete all files in the working directory (excluding the .git directory, of course)

  • git clean -d -x -f (-d: directories, -x: ignored files, -f: force. Replace -f with -n for dry run)

And then follow up with a git reset --hard and git checkout.

One more thought is to try a git reset --hard HEAD~N - i.e resetting a number of commits back, and hoping the pull will work and fast-forward the local.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Chamila Chulatunga
  • 4,856
  • 15
  • 17