gitpython修剪本地分支

2024-04-26 03:30:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过gitpython实现git remote prune origin。我可以通过使用Repo(path).remote('origin').stale_refs获得要删除的分支

你知道我该怎么修剪吗


Tags: pathgitremote分支repoorigingitpythonrefs
1条回答
网友
1楼 · 发布于 2024-04-26 03:30:01

从我的经验尝试来看,这似乎是可行的:

repo = git.Repo(path)
for branch in repo.remote('origin').stale_refs:
  if isinstance(branch, git.refs.remote.RemoteReference):
    type(branch).delete(repo, branch)
  else:
    pass  # it seems stale_refs can include tags (etc?)

相关问题 更多 >