使用git删除不在本地存储库中的分支

发布于 2024-09-15 04:57:27 字数 109 浏览 2 评论 0原文

当我在 GitHub 上分叉时,我的一个 git 存储库上有一堆分支。我不希望我的 GitHub 分支有这些分支。

有什么方法可以删除 GitHub 存储库中不在本地存储库中的所有分支吗?

There's a bunch of branches on one of my git repo's that I got when I forked it on GitHub. I don't want my GitHub fork to have these branches.

Is there any way that I can delete all the branches on my GitHub repo that are not in my local repo?

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

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

发布评论

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

评论(2

辞旧 2024-09-22 04:57:29

git push --mirror将使远程上的引用与本地存储库中的引用相匹配,包括删除本地没有的分支。

来自git帮助推送

--mirror
    Instead of naming each ref to push, specifies that all refs under
    refs/ (which includes but is not limited to refs/heads/,
    refs/remotes/, and refs/tags/) be mirrored to the remote
    repository. Newly created local refs will be pushed to the remote
    end, locally updated refs will be force updated on the remote end,
    and deleted refs will be removed from the remote end. This is the
    default if the configuration option remote.<remote>.mirror is set.

git push --mirror <origin> will make the refs on the remote match those in the local repository, including deleting branches that you don't have locally.

From git help push:

--mirror
    Instead of naming each ref to push, specifies that all refs under
    refs/ (which includes but is not limited to refs/heads/,
    refs/remotes/, and refs/tags/) be mirrored to the remote
    repository. Newly created local refs will be pushed to the remote
    end, locally updated refs will be force updated on the remote end,
    and deleted refs will be removed from the remote end. This is the
    default if the configuration option remote.<remote>.mirror is set.
醉生梦死 2024-09-22 04:57:29

您可以通过推送空分支来删除远程分支:

$ git push origin :branch-to-delete

You can delete remote branches my pushing an empty branch:

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