Skip to content

Commit

Permalink
Add script for deleting local merged branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiel ten Brinke committed Jun 16, 2016
1 parent 2ceef18 commit 8be141d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion archive_merged_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
remotely. Before each operation, the user is asked for confirmation.
"""
# This dependency can be found on github: https://github.com/Chiel92/python-shellout
from shellout import get, out, confirm
from pyshellout import get, out, confirm


# Tag merged branches
Expand Down
34 changes: 34 additions & 0 deletions delete_local_merged_branches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Delete local branches that are merged into master.
Before each operation, the user is asked for confirmation.
"""
import argparse

# This dependency can be found on github: https://github.com/Chiel92/python-shellout
from pyshellout import get, out, confirm


parser = argparse.ArgumentParser()
parser.add_argument('master',
help='Name of the master branch. Defaults to \'master\'.',
nargs='?', default='master')
args = parser.parse_args()
master = args.master


# Get merged branches
merged_branches = [line.strip() for line in
get(r'git branch --merged {}', master, critical=True).n]
merged_branches = [branch for branch in merged_branches
if branch != '' and not '*' in branch and not branch == master]

print('Merged local branches:')
for branch in merged_branches:
print(' ' + branch)


print()
for branch in merged_branches:
if confirm('Delete local branch {}?', branch):
out('git branch -d {}', branch)

0 comments on commit 8be141d

Please sign in to comment.