SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from git import Repo
  2.  
  3. repo_path = input("Repo path: ")
  4. repo = Repo(repo_path)
  5.  
  6. branches = []
  7. remotes = []
  8.  
  9. print("Load remote branches list")
  10. for r in repo.remotes.origin.fetch():
  11.     remotes.append(r.name)
  12.  
  13. print("Load local branches list and check exist in remote")
  14. for b in repo.branches:
  15.     tb = b.tracking_branch()
  16.     if tb:
  17.         try:
  18.             remotes.index(tb.name)
  19.         except:
  20.             branches.append(b.name)
  21.  
  22. print("Found deleted branches")
  23. print(*branches, sep="\n")
  24.  
  25. answer = input("Remove locals (y/n)?: ")
  26.  
  27. if answer == "y":
  28.     print("Current branch: ", repo.active_branch)
  29.     name = input("Checkout to branch before delete (to pass to remain in current): ")
  30.     if name:
  31.         repo.git.checkout(name)
  32.  
  33.     for name in branches:
  34.         print("Remove ", name)
  35.         repo.git.branch(D=name)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top