Created
April 16, 2023 08:38
-
-
Save gtklocker/c94de1fca6bbfd033ddff9201f456b0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
if __name__ == "__main__": | |
current_branch = subprocess.check_output(["git", "branch", "--show-current"]).rstrip() | |
if not current_branch: | |
raise Exception("need to be checked out to a named git branch") | |
merged_branches_with_upstream = subprocess.check_output( | |
["git", "branch", "--format", "%(refname:short) %(upstream:short)", "--merged"] | |
).split(b"\n") | |
for bu in merged_branches_with_upstream: | |
if not bu: | |
continue | |
(branch, upstream) = bu.split(b" ") | |
if branch == current_branch: | |
continue | |
print(f"deleting branch {branch}...") | |
subprocess.check_call(["git", "branch", "-d", branch]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment