完整的信息:

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拉-p

-p --prune Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a --tags option. However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning. Supplying --prune-tags is a shorthand for providing the tag refspec.

——来源:https://git-scm.com/docs/git-pull文档/ git-pull.txt——p

其他回答

只需删除\.git\refs\remotes\origin下的文件夹和文件。 工作,当你没有未推送的更改。

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

硬重启也会解决这个问题

git reset --hard origin/master

永久解决

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 branch --unset-upstream