Skip to content

Instantly share code, notes, and snippets.

@mariok
Created November 6, 2016 10:31
Show Gist options
  • Select an option

  • Save mariok/79477e6162ef5ea8809751767f4056ce to your computer and use it in GitHub Desktop.

Select an option

Save mariok/79477e6162ef5ea8809751767f4056ce to your computer and use it in GitHub Desktop.
Helper-script for Git, which deletes all "dev_*" branches from a remote-repository, which have already been merged into branch "master"
#!/bin/bash
# Helper-script for Git
# Deletes all branches from a remote-repository, which have already been merged into branch "master"
# only branches starting with prefix "dev_" will be deleted
#
# based on https://gist.github.com/schacon/942899
# fetch the latest state from the remote repo, removing all remotely deleted branches locally as well
git fetch -p
# display the list of branches, which will be deleted
git branch -r --merged origin/master | grep origin/dev_ | awk '{sub(/origin\//,"");print}'
# delete the branches from the remote-repository
git branch -r --merged origin/master | grep origin/dev_ | awk '{sub(/origin\//,"");print}' | xargs git push origin --delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment