Last active
November 21, 2018 02:46
-
-
Save Benhgift/eeea2449b7fd637b746aa57aa7efafb3 to your computer and use it in GitHub Desktop.
remove all git branches except for the few you want
This file contains hidden or 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 | |
from subprocess import getoutput | |
import re | |
def main(): | |
branches_dict = branches() | |
save_nums = input('type branch numbers to NOT delete, seperated by spaces\n') | |
save_nums = map(int, re.findall(r'\d+', save_nums)) | |
for num in save_nums: | |
branches_dict.pop(num) | |
for k, v in branches_dict.items(): | |
print(k, v) | |
input('will delete these, press ctrl-c to stop, otherwise return...') | |
for branch in branches_dict.values(): | |
getoutput('git branch -D ' + branch) | |
return branches_dict | |
def branches(): | |
branches = getoutput('git branch').split('\n') | |
branches = [b for b in branches if 'master' not in b] | |
return print_branches_return_dict(branches) | |
def print_branches_return_dict(branches): | |
branch_dict = {} | |
for i, b in enumerate(branches): | |
if i < 10: | |
print(i, '', b) | |
else: | |
print(i, b) | |
branch_dict[i] = b | |
return branch_dict | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment