Advertisement
Guest User

Untitled

a guest
May 31st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #!/bin/sh
  2. #/ Usage: clean-merged-branches
  3.  
  4. #/ Delete locally merged branches
  5. set -e
  6.  
  7. # show usage maybe
  8. [ "$1" = "--help" ] && {
  9. grep '^#/' <"$0"| cut -c4-
  10. exit 0
  11. }
  12.  
  13. # fetch and prune remote branches
  14. git fetch origin --prune
  15.  
  16. # Delete merged local branches
  17. git branch --merged | grep -v '*' | grep -v master | xargs git br -d
  18.  
  19. # grab list of merged branches
  20. branches=$(
  21. git branch -r --merged |
  22. sed 's@origin/@@'
  23. )
  24.  
  25. # bail out with no branches
  26. [ -z "$branches" ] && {
  27. echo "no merged branches detected" 1>&2
  28. exit 0
  29. }
  30.  
  31. # delete the branches or just show what would be done without -f
  32. echo "Merged branches on origin: " 1>&2
  33. echo "$branches"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement