Skip to content

Instantly share code, notes, and snippets.

@IrishPrime
Created October 3, 2017 15:31
Show Gist options
  • Select an option

  • Save IrishPrime/3bdb9e4dde74b2e68c74d29801a6a76a to your computer and use it in GitHub Desktop.

Select an option

Save IrishPrime/3bdb9e4dde74b2e68c74d29801a6a76a to your computer and use it in GitHub Desktop.
Remove merged branches
#!/bin/bash
# Delete remote branches which have been merged into master, excluding the
# current branch, then remove local branches pointing to remote branches which
# have been deleted.
# Test
git branch -r --merged master | grep -v -e $(git symbolic-ref --short HEAD) -e master | sed 's/origin\///'
# Delete
# git branch -r --merged master | grep -v -e $(git symbolic-ref --short HEAD) -e master | sed 's/origin\///' | xargs -n 1 git push --delete origin
# git fetch --prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment