清理远程 Git 分支

发布于 2024-09-25 08:16:26 字数 667 浏览 3 评论 0原文

我已经将 SVN 存储库移至 Git,可能由于多次克隆,我现在留下了一堆看起来像

BranchA
origin/BranchA
remotes/BranchA
remotes/origin/BranchA
remotes/origin/origin/BranchA

同一分支被列出多次的分支。我该如何清理这个烂摊子。有> 50 个分支,有些根本不需要,其余的我只要拥有一次就很高兴了。

编辑:

show origin 在某种情况下的样子:

Remote branches:
BranchA tracked
origin/BranchA tracked

......

Local branches configured for 'git pull':
origin/BranchA merges with remote BranchA

这就是 git Remote

Local refs configured for 'git push':
BranchA pushes to BranchA (up to date)
origin/BranchA pushes to origin/BranchA (up to date)

I have moved an SVN repo to Git and probably due to a number of clonings, I'm now left with a bunch of branches that look like

BranchA
origin/BranchA
remotes/BranchA
remotes/origin/BranchA
remotes/origin/origin/BranchA

i.e. the same branch is listed a number of times. How can I clean this mess up. There are > 50 branches, some are not needed at all, and for the rest I'd be happy with just having them once.

EDIT:

This is what git remote show origin looks like for a certain case:

Remote branches:
BranchA tracked
origin/BranchA tracked

...

Local branches configured for 'git pull':
origin/BranchA merges with remote BranchA

...

Local refs configured for 'git push':
BranchA pushes to BranchA (up to date)
origin/BranchA pushes to origin/BranchA (up to date)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2024-10-02 08:16:26

您可以使用以下命令删除这些分支:

git push origin :branch_name

要删除 BranchA 分支:

git push origin :BranchA

要删除 origin/BranchA 分支:

git push origin :origin/BranchA

或者,您可以使用 gitbranch -dr BranchA等等。

删除除 BranchAorigin/BranchA 之外的所有分支。您可能已删除 origin 遥控器,在这种情况下,您应该删除 remotes 遥控器并将其重新添加为 origin 遥控器。

You can remove these branches by using this command:

git push origin :branch_name

To remove the BranchA branch:

git push origin :BranchA

To remove the origin/BranchA branch:

git push origin :origin/BranchA

Alternatively you could use git branch -dr BranchA and so on.

Remove every branch except BranchA and origin/BranchA. You may have deleted the origin remote, in which case you should remove the remotes remote and re-add it as the origin remote.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文