Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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 -
# 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