完整的信息:

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 gc --prune=now
git remote prune origin
git pull

其他回答

如果你在一个不区分大小写的文件系统(Windows或OS X)下运行git,如果有两个同名但大写不同的分支,就会发生这种情况,例如user_model_changes和user_model_changes,因为两个远程分支将匹配相同的跟踪引用。

删除错误的远程分支(你不应该有只有大小写不同的分支),然后git远程删除原点,一切都应该正常工作

同样的情况在这里,但没有关于张贴的评论在我的情况下是正确的,我只有一个分支(master),只使用Unix文件系统,这个错误随机发生时,我运行git fetch -progress -修剪起源和分支是前方或'origin/master'。没有人可以提交,只有1个用户可以推送。

注意:我在acme存储库中有一个子模块,acme有新的子模块更改(新提交),我需要先用git子模块更新做一个子模块更新。

[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

要解决这个问题(在我的例子中),如果你的分支在原点之前,只需运行第一个git push。

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

git branch --unset-upstream

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

我尝试了多种选择,但没有一个对我有效。下面的命令对我很有用。把它放在这里,如果它能帮助人们,以防其他选择不起作用。

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