git pull error :error: remote ref is at but expected

GitPullGit Pull

Git Problem Overview


Full message:

error: Ref refs/remotes/origin/user is at 3636498c2ea7735fdcedc9af5ab3c8689e6abe77 but expected a21359c6cc2097c85775cde6a40105f4bd7100ec
From github.com:{github project url}
 ! a21359c..6273ffc  user -> origin/user  (unable to update local ref)

Git Solutions


Solution 1 - Git

If you are running git under a file system that is not case sensitive (Windows or OS X) this will occur if there are two branches with the same name but different capitalisation, e.g. user_model_changes and User_model_changes as both of the remote branches will match the same tracking ref.

Delete the wrong remote branch (you shouldn't have branches that differ only by case) and then git remote prune origin and everything should work

Solution 2 - Git

Permanent Fix

git update-ref -d resolved my instance of this error, e.g.

git update-ref -d refs/remotes/origin/user

Note that this doesn't impact remote.

In my case, a subsequent git fetch fetched that branch again, and following git fetches/pulls no longer gave the error "remote ref is at but expected".

If that doesn't work, a temporary fix:

Note also that if you don't care about the branch in question (e.g. you just want to update master, not origin/user), a git pull workaround is to fetch then just merge the particular branch you care about, e.g.

git fetch # may give an error for a particular branch, but other branches will still be successfully fetched
git merge origin/master

Solution 3 - Git

Just delete the folders and files under \.git\refs\remotes\origin. Works, when u don't have unpushed changes.

Solution 4 - Git

Use the below two commands one by one.

git gc --prune=now

git remote prune origin

This will resolve your issue.

Solution 5 - Git

I ran this to solve the problem:

git gc --prune=now

Solution 6 - Git

I had to remove my branch from my command line at:

.git\refs\remotes\{my remote}\{**my branch**}

and then manually doing:

git pull [remote_name] [branch_name]

I was able to pull the changes.

Note: I was using SourceTree and was unable to do the pull.

Solution 7 - Git

A hard reset will also resolve the problem

git reset --hard origin/master

Solution 8 - Git

Clearer Steps

  1. in terminal

     cd /.git/refs/remotes/origin
    
  2. do ls, you will see some branches and HEAD

  3. Remove the branch you think has the problem

     rm branchname
    
  4. If it did not work, delete all branches/HEAD

  • you may wana pull

Hope it works now.

Solution 9 - Git

Unfortunately GIT commands like prune and reset or push didn't work for me. Prune worked once and then the issue returned.

The permanent solution which worked for me is to edit a git file manually. Just go to the project's .git folder and then open the file packed-refs in a text editor like Notepad++. Then navigate to the row with the failing branch and update its guid to the expected one.

If you have a message like:

> error: cannot lock ref 'refs/remotes/origin/feature/branch_xxx': is at 425ea23facf96f51f412441f41ad488fc098cf23 but expected 383de86fed394ff1a1aeefc4a522d886adcecd79

then in the file find the row with refs/remotes/origin/feature/branch_xxx. The guid there will be the expected (2nd) one - 383de86fed394ff1a1aeefc4a522d886adcecd79. You need to change it to the real (1st) one - 425ea23facf96f51f412441f41ad488fc098cf23.

Repeat for the other failing branches and you'll be good to proceed. Sometimes after re-fetch I had to repeat for the same branches which i already 'fixed' earlier. On re-fetch GIT updates guids and gives you the latest one.

Anyways the issue isn't a show stopper. The branch list gets updated. This is rather a warning.

Solution 10 - Git

Try this, it worked for me. In your terminal: git remote prune origin.

Solution 11 - Git

I have tried multiple options but no option worked for me. Below command worked for me. Putting it here, if it can help people incase other options does not work.

git pull -p

Solution 12 - Git

git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin git reflog expire --expire=now --all git gc --prune=now

Solution 13 - Git

I had the same problem which was caused because I resetted to an older commit even though I already pushed to the remote branch.

I solved it by deleting my local branch then checking out the origin branch git checkout origin/my_branch and then executing git checkout my_branch

Solution 14 - Git

Same case here, but nothing about comments posted it's right in my case, I have only one branch (master) and only use Unix file system, this error occur randomly when I run git fetch --progress --prune origin and branch is ahead or 'origin/master'. Nobody can commit, only 1 user can do push.

NOTE: I have a submodule in acme repository, and acme have new submodule changes (new commits), I need first do a submodule update with git submodule update.

[2014-07-29 13:58:37] Payload POST received from Bitbucket
[2014-07-29 13:58:37] Exec: cd /var/www/html/acme
---------------------
[2014-07-29 13:58:37] Updating Git code for all branches
[2014-07-29 13:58:37] Exec: /usr/bin/git checkout --force master
[2014-07-29 13:58:37] Your branch is ahead of 'origin/master' by 1 commit.
[2014-07-29 13:58:37]   (use "git push" to publish your local commits)
[2014-07-29 13:58:37] Command returned some errors:
[2014-07-29 13:58:37] Already on 'master'
---------------------
[2014-07-29 13:58:37] Exec: /usr/bin/git fetch --progress --prune origin
[2014-07-29 13:58:39] Command returned some errors:
[2014-07-29 13:58:39] error: Ref refs/remotes/origin/master is at 8213a9906828322a3428f921381bd87f42ec7e2f but expected c8f9c00551dcd0b9386cd9123607843179981c91
[2014-07-29 13:58:39] From bitbucket.org:acme/acme
[2014-07-29 13:58:39]  ! c8f9c00..8213a99  master     -> origin/master  (unable to update local ref)
---------------------
[2014-07-29 13:58:39] Unable to fetch Git data

To solve this problem (in my case) simply run first git push if your branch is ahead of origin.

Solution 15 - Git

I know this is old, but I have my own fix. Because I'm using source tree, this error happens because someone create a new branch. The source tree is confused about this. After I press "Refresh" button beside the "remote branch to pull" combobox, it seems that sourcetree has updated the branch list, and now I can pull successfully.

Solution 16 - Git

I faced same issue , I just deleted the remote branch and created new branch from the master and merged my changes from old feature branch to new feature branch . Now i tried pull and push requests its worked for me

Solution 17 - Git

I have faced this issue and my solution is given below:

Step 1:

  1. Please run this command first.

    git gc --Prune=now

Step 2:

  1. If there is no error after running Step 1 command then run this below command in your terminal.

    git remote Prune Origin

I hope this will fix your problem.

Solution 18 - Git

After searching constantly, this is the solution that worked for me which entails unsetting/removing the Upstream

git branch --unset-upstream

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSanjeev Kumar DangiView Question on Stackoverflow
Solution 1 - GitkrijestaView Answer on Stackoverflow
Solution 2 - GitJDiMatteoView Answer on Stackoverflow
Solution 3 - GitPrakash SaravananView Answer on Stackoverflow
Solution 4 - GitNarender GusainView Answer on Stackoverflow
Solution 5 - Gitelad silverView Answer on Stackoverflow
Solution 6 - Gitjogam5View Answer on Stackoverflow
Solution 7 - GitmruanovaView Answer on Stackoverflow
Solution 8 - GitshareefView Answer on Stackoverflow
Solution 9 - GitAndrei S.View Answer on Stackoverflow
Solution 10 - GitRanganatha G VView Answer on Stackoverflow
Solution 11 - GitManojPView Answer on Stackoverflow
Solution 12 - GitLucianoView Answer on Stackoverflow
Solution 13 - GitBlackView Answer on Stackoverflow
Solution 14 - GitTecnocatView Answer on Stackoverflow
Solution 15 - GitChen Li YongView Answer on Stackoverflow
Solution 16 - GitVenu GopalView Answer on Stackoverflow
Solution 17 - GitMadeefar AbbasView Answer on Stackoverflow
Solution 18 - GitSugoi ReedView Answer on Stackoverflow