git:修剪/删除旧分支;错误:推送某些引用失败“;
以下是我的GitHub repo上的一些远程分支的列表:git:修剪/删除旧分支;错误:推送某些引用失败“;,git,github,Git,Github,以下是我的GitHub repo上的一些远程分支的列表: $ git branch -a warning: ignoring broken ref refs/remotes/remote/HEAD * master origin restoration-effort2 remotes/origin/master remotes/remote/master remotes/remote/carousel remotes/bridgent/animate remot
$ git branch -a
warning: ignoring broken ref refs/remotes/remote/HEAD
* master
origin
restoration-effort2
remotes/origin/master
remotes/remote/master
remotes/remote/carousel
remotes/bridgent/animate
remotes/bridgent/enlarged-hover
remotes/bridgent/master
remotes/bridgent/Rayom-generator-app
remotes/bridgent/scripts
remotes/bridgent/bridgent-carousel
我的意图/目标是删除所有以“remotes”(但不是两个“master”)开头的
当我尝试删除它们时,我得到:
error: unable to delete 'remote/bridgent-carousel': remote ref does not exist
error: failed to push some refs to 'git@github.com:Nostrad/<project_name>.git'
TL;博士
运行git-remote
并查看是否有名为remote
和bridgent
的远程设备。(使用git remote-v
查看与每个远程服务器关联的URL。)
如果您不想将远程设备命名为remote
,请使用git remote remove remote
将其删除。这也将删除其所有远程跟踪名称。如果需要,对bridgent重复上述步骤
如果确实要保留这些远程设备,但要删除与这些远程设备关联的任何远程跟踪名称,请运行:
git fetch remote --prune
和/或:
git fetch bridgent --prune
您还可以运行:
git fetch --all --prune
(或缩写为git fetch-a-p)。--all
表示联系所有遥控器。或者,您可以使用git远程更新--prunegit远程更新
默认为从所有远程获取。git fetch
的默认值通常只是调用并更新origin
。1
1技术上,
git fetch
的默认值是基于当前分支的上游调用远程,但如果未设置,则使用origin
。大多数Git存储库往往只有一个远程存储库,名为origin
,所以这很好。您的Git存储库有三个远程,因此它没有
git远程更新的默认设置特别复杂;有关详细信息,请参阅。这似乎是为更大的镜像站点而设计的,比如我曾经为一家中型公司运行的站点
长的 让我引用这一部分作为重点,因为它是: 如果我们从每一行取出
遥控器/
部分,我们得到:
origin/master
remote/master
remote/carousel
bridgent/animate
bridgent/enlarged-hover
bridgent/master
[snip]
如果我们进一步从剩余的第一个/
中删除该零件,并消除重复项,我们将得到以下列表:
origin
remote
bridgent
这是一个遥控器列表
如果运行git remote
,您应该会看到相同的名称列表。(如果您没有,我们要解决的问题与我认为您遇到的问题有些不同。)
现在:
以下是我的GitHub repo上的一些远程分支的列表:
$ git branch -a
warning: ignoring broken ref refs/remotes/remote/HEAD
* master
origin
restoration-effort2
remotes/origin/master
remotes/remote/master
remotes/remote/carousel
remotes/bridgent/animate
remotes/bridgent/enlarged-hover
remotes/bridgent/master
remotes/bridgent/Rayom-generator-app
remotes/bridgent/scripts
remotes/bridgent/bridgent-carousel
从技术上讲,这些都不在GitHub存储库中。它们位于(或位于)您的本地存储库、笔记本电脑或台式机上。GitHub上还有另一个不同的存储库;这是您的GitHub存储库
远程和远程跟踪名称
请记住,Git是一个分布式版本控制系统。因此,通常有两个、三个、十个甚至数百万个存储库。每个存储库都有自己的分支名称。某些存储库的所有克隆共享的不是分支,而是提交。提交是共享的内容。分支名称只是帮助每个存储库记住其提交。每个提交都有一个唯一的哈希ID,在每个存储库中都是相同的。存储库要么有提交,然后有散列ID;或者它没有提交,也没有散列ID
当你让你的Git在GitHub上调用另一个Git时,你的Git会询问他们的提交情况。他们会说,例如,我有我的master
作为提交a123456…
你的Git检查:我有a123456…
?如果你有它,你的Git会说OK,我已经有了,你不需要得到它。如果你没有,你的Git会说啊,请给我a123456…
,他们的Git现在提供了提交的父提交。Git检查您是否有该提交。如果没有,您的Git会询问a123456…
的父级,他们会提供提交的父级-a123456…
的祖父母,您的Git会检查哈希ID,依此类推
最后,你的Git从他们的Git中获得了他们在主机上的所有提交,而你的Git根本没有这些提交。现在你有了你所有的承诺加上他们所有的承诺。您的master
很可能就是这个a123456…
commit。或者,您的master
可能是其他提交。不管是什么情况,您的Git现在都会创建一个新名称,或者更新一个现有名称,以记住它们的主文件
您的Git内存中的Git分支名称是您对这个特定“其他Git”的远程跟踪名称。GitHub上的另一个Git有一个URL;远程名称origin
存储此URL。但是如果你有不止一个“其他Git”呢
您的Git可以调用不同的Git存储库,可能名称为bridgent
。此远程名称,bridgent
,存储URL。这就是你的Git调用另一个Git的方式。当你的Git调用另一个Git时,他们会这样说:我有一个名为animate
的分支,一个名为放大悬停
的分支和一个名为master
的分支。我的动画
是提交b789abc…
,我的放大悬停
是提交fedcba9…
,我的主机
是
您的Git将从bridgent
Git获得它拥有的、您没有的任何提交。然后,Git将创建或更新您的bridgent/*
名称。这些包含Git从Git获得的哈希ID,Git的URL存储在名称bridgent
下
因此,由于您有origin
和remote
和bridgent
,这意味着您的Git记录了三个不同的远程。每个远程存储一个URL;在这个URL上,一些Git会在你拨打它的号码时应答。该Git有一个分支名称列表。每个分支名称通过散列ID标识一些特定的提交。您的Git确保它也有这些提交,然后为这些其他Git代表创建或更新远程跟踪名称
remotes/origin/master
remotes/remote/master
remotes/remote/carousel
remotes/bridgent/animate
[snip]
origin/master
remote/master
remote/carousel
bridgent/animate
bridgent/enlarged-hover
bridgent/master
[snip]
origin
remote
bridgent
git branch
git branch -r
$ git push origin --delete remote/bridgent-carousel
error: unable to delete 'remote/bridgent-carousel': remote ref does not exist
error: failed to push some refs to 'git@github.com:Nostrad/<project_name>.git'
$ git remote -v
origin git@github.com:Nostrad/<project_name>.git (fetch)
origin git@github.com:Nostrad/<project_name>.git (push)
remote git@github.com:Nostrad/<former_project_name>.git (fetch)
remote git@github.com:Nostrad/<former_project_name>.git (push)
bridgent git@github.com:bridgent/<project_name>.git (fetch)
$ git remote remove remote
$ git remote remove bridgent
$ git fetch --prune
$ git push origin --delete
git branch -a
warning: ignoring broken ref refs/remotes/remote/HEAD
* master
origin
restoration-effort2
remotes/origin/master
$ git fetch remote --prune
$ git fetch bridgent --prune
$ git fetch --all --prune