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)
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.
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin git reflog expire --expire=now --all git gc --prune=now
Clearer Steps
in terminal
cd /.git/refs/remotes/origin
do ls
, you will see some branches and HEAD
Remove the branch you think has the problem
rm branchname
If it did not work, delete all branches/HEAD
Hope it works now.
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.
After searching constantly, this is the solution that worked for me which entails unsetting/removing the Upstream
git branch --unset-upstream
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
A hard reset will also resolve the problem
git reset --hard origin/master
I ran this to solve the problem:
git gc --prune=now
Just delete the folders and files under \.git\refs\remotes\origin
.
Works, when u don't have unpushed changes.
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
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".
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
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
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.
Try this, it worked for me.
In your terminal: git remote prune origin
.
Use the below two commands one by one.
git gc --prune=now
git remote prune origin
This will resolve your issue.
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.
Source: Stackoverflow.com