Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Created April 26, 2019 17:12
Show Gist options
  • Save erinxocon/6f6e1f61dcdbce108b9f5c7b93266368 to your computer and use it in GitHub Desktop.
Save erinxocon/6f6e1f61dcdbce108b9f5c7b93266368 to your computer and use it in GitHub Desktop.
import delegator
c = delegator.run('git branch -r --merged').pipe('grep -v -E "HEAD|store|stage"')
merged_branches = c.out.splitlines()[:-1]
for i in merged_branches:
stripped = i.strip()
replaced = stripped.replace('origin/', '')
try:
c = delegator.run('git show --format="%ci %cr %an" {0}'.format(stripped)).pipe('head -n 1')
except BrokenPipeError as e:
print(stripped)
delegator.run('git push origin --delete {0}'.format(replaced))
with open('removed.txt', mode='a', encoding='utf-8') as f:
f.write('{0} {1}\n'.format(c.out.strip(), stripped))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment