Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from git import Repo
- repo_path = input("Repo path: ")
- repo = Repo(repo_path)
- branches = []
- remotes = []
- print("Load remote branches list")
- for r in repo.remotes.origin.fetch():
- remotes.append(r.name)
- print("Load local branches list and check exist in remote")
- for b in repo.branches:
- tb = b.tracking_branch()
- if tb:
- try:
- remotes.index(tb.name)
- except:
- branches.append(b.name)
- print("Found deleted branches")
- print(*branches, sep="\n")
- answer = input("Remove locals (y/n)?: ")
- if answer == "y":
- print("Current branch: ", repo.active_branch)
- name = input("Checkout to branch before delete (to pass to remain in current): ")
- if name:
- repo.git.checkout(name)
- for name in branches:
- print("Remove ", name)
- repo.git.branch(D=name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement