完整的信息:

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 update-ref -d解决了这个错误的实例,例如:

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

注意,这不会影响远程。

在我的例子中,后续的git获取再次获取该分支,并且后续的git获取/拉不再给出错误“remote ref is at but expected”。

如果这不起作用,临时修复:

还要注意的是,如果你不关心所讨论的分支(例如,你只想更新master,而不是origin/user),一个git pull的变通方法是获取然后合并你所关心的特定分支,例如。

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

其他回答

我知道这很旧了,但我有自己的办法。因为我使用的是源树,这个错误发生是因为有人创建了一个新的分支。源树对此感到困惑。在我按下“remote branch to pull”组合框旁边的“Refresh”按钮后,似乎sourcetree已经更新了分支列表,现在我可以成功拉起。

我也遇到了同样的问题,我只是删除了远程分支,并从master中创建了新的分支,并将我从旧功能分支到新功能分支的更改合并在一起。现在我尝试了拉和推的要求,它为我工作

经过不断的搜索,这是对我有效的解决方案,需要清除/移除上游

git branch --unset-upstream

永久解决

Git update-ref -d解决了这个错误的实例,例如:

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

注意,这不会影响远程。

在我的例子中,后续的git获取再次获取该分支,并且后续的git获取/拉不再给出错误“remote ref is at but expected”。

如果这不起作用,临时修复:

还要注意的是,如果你不关心所讨论的分支(例如,你只想更新master,而不是origin/user),一个git pull的变通方法是获取然后合并你所关心的特定分支,例如。

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

我运行这个来解决问题:

git gc --prune=now