Skip to content

Instantly share code, notes, and snippets.

@techtonik
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techtonik/b3f0d4b9a56dbacb3afc to your computer and use it in GitHub Desktop.
Save techtonik/b3f0d4b9a56dbacb3afc to your computer and use it in GitHub Desktop.
git: Remove local branches merged upstream
#!/usr/bin/env python
# Remove merged git branches. Cross-platform way to execute:
#
# git branch --merged | grep -v master | xargs git branch -d
#
# Requires gitapi - https://bitbucket.org/haard/gitapi
# License: Public Domain
import gitapi
repo = gitapi.Repo('.')
output = repo.git_command('branch', '--merged').strip()
for branch in output.split('\n'):
branch = branch.strip()
if branch.strip(' *') != 'master':
print(repo.git_command('branch', '-d', branch).strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment