代码之家  ›  专栏  ›  技术社区  ›  xenoterracide

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

  •  4
  • xenoterracide  · 技术社区  · 15 年前

    在我的一个git回购上有一堆分支,是我在GitHub上分叉时得到的。我不想让我的GitHub叉子有这些树枝。

    有没有什么方法可以删除GitHub repo上所有不在本地repo中的分支?

    2 回复  |  直到 9 年前
        1
  •  7
  •   mkarasek    15 年前

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

    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.
        2
  •  1
  •   mipadi    15 年前

    您可以删除远程分支,也可以删除空分支:

    $ git push origin :branch-to-delete