Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/env bash -e
  2.  
  3. REMOTE="$1"
  4. BRANCH="$2"
  5.  
  6. if [ !$REMOTE ]; then
  7. REMOTE="origin"
  8. fi
  9.  
  10. if [ !$BRANCH ]; then
  11. BRANCH="master"
  12. fi
  13.  
  14. git fetch $REMOTE
  15. MERGEDBRANCHES=(`git log $REMOTE/$BRANCH --merges | ack --match "Merge pull request" | ack -o --match "[A-z0-9\-_\/]+$" | sed -E 's_^[A-z0-9\-_]+/__'`)
  16. LOCALBRANCHES=(`git branch | ack -o --match "[A-z0-9-_\/]+$"`)
  17. TOREMOVE=()
  18.  
  19. SEARCH=" ${MERGEDBRANCHES[*]} "
  20. for BRANCH in "${LOCALBRANCHES[@]}"; do
  21. if [[ $SEARCH =~ " $BRANCH " ]]; then
  22. TOREMOVE+=($BRANCH)
  23. fi
  24. done
  25.  
  26. for RMBRANCH in "${TOREMOVE[@]}"; do
  27. git branch -D $RMBRANCH
  28. done
  29.  
  30. git remote prune $REMOTE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement