完整的信息:

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

其他回答

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

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

不幸的是,GIT命令如修剪、重置或推送对我不起作用。修剪工作了一次,然后问题又回来了。

对我有效的永久解决方案是手动编辑git文件。只需转到项目的.git文件夹,然后在文本编辑器(如notepad++)中打开packd -refs文件。然后导航到失败的分支所在行,并将其guid更新为预期的guid。

如果你有这样的信息:

错误:不能锁定ref 'refs/remotes/origin/feature/branch_xxx':是在425ea23facf96f51f412441f41ad488fc098cf23,但预期383de86fed394ff1a1aeefc4a522d886adcecd79

然后在文件中找到带有refs/remotes/origin/feature/branch_xxx的行。这里的guid将是预期的(第二个)- 383de86fed394ff1a1aeefc4a522d886adcecd79。您需要将其更改为真正的(第一个)- 425ea23facf96f51f412441f41ad488fc098cf23。

对其他失败的分支重复操作,您就可以继续了。有时在重新获取后,我不得不重复相同的分支,我已经“固定”之前。在重新获取时,GIT更新guids并给你最新的一个。

无论如何,这个问题不是一个节目的中止。分支列表得到更新。这是一个相当大的警告。

我遇到过这个问题,我的解决方案如下:

步骤1:

请先执行该命令。 git gc—Prune=现在

步骤2:

如果运行步骤1命令后没有错误,则在终端中运行下面的命令。 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。

清晰的步骤

在终端 cd / . / /遥控器/参考文献来源 做ls,你会看到一些树枝和头部 移除你认为有问题的分支 rm branchname 如果它不起作用,删除所有分支/HEAD 你可能想拉一把

希望它现在有用。