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

Viewed 171737

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)
19 Answers

Use the below two commands one by one.

git gc --prune=now

git remote prune origin

This will resolve your issue.

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.

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

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

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

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.

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.

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

I was unable to pull from my Git repo and getting same error as mentioned above. In My case, I performed steps as right clicked on the project folder -> clicked on settings -> clicked on Remote -> clicked on remove button -> provide details for configuration Remote: "origin" , URL:"" in this setting page. -> then clicked on 'Add New/Save' button-> clicked ok.

After above changes, I am able to pull/fetch my desired branch successfully.

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

git branch --unset-upstream
Related