-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-chop.py
35 lines (27 loc) · 1.02 KB
/
git-chop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from pygit2 import Repository
'''
A simple git command to quickly clean out your old branches.
'''
if os.path.exists("./.git"):
local_repo_name = os.getcwd() + "\\.git"
repo = Repository(local_repo_name)
print()
branches_to_remove = []
for branch in repo.branches.local:
if (branch == "master" or branch == "master-cached" or (len(branch) == 3 and branch[1:] == "SW")):
continue
answer = input("Delete branch " + branch + " (Y/N)?")
if (answer.lower() == 'y' or answer.lower() == 'yes'):
branches_to_remove.append(branch)
print()
print("Warning! The following local branches will be deleted:")
for branch_to_remove in branches_to_remove:
print("\t" + branch_to_remove)
print()
answer = input("Are you sure you want to delete those branches (Y/N)?")
if (answer.lower() == 'y' or answer.lower() == 'yes'):
print("\n")
for branch_to_remove in branches_to_remove:
repo.references.delete('refs/heads/' + branch_to_remove)
print(branch_to_remove + " has been deleted.")