Guest User

Untitled

a guest
Aug 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$1" = "rm" ]; then
  4. branches_file=${2:-"orphaned-branches.txt"}
  5. echo "Removing branches specified in $branches_file"
  6. while read branch; do
  7. git branch -D $branch
  8. done < $branches_file
  9. exit 0
  10. fi
  11.  
  12. tmpdir=`mktemp -d`
  13. git ls-remote --refs --heads | awk '{print $2}' | sed 's/refs\/heads\///' | while read branch; do
  14. mkdir -p "${tmpdir}/${branch}"
  15. done
  16.  
  17. rm -f orphaned-branches.txt
  18. git branch | sed 's/\* //' | while read branch; do
  19. [ ! -d "${tmpdir}/${branch}" ] && echo $branch >> orphaned-branches.txt
  20. done
  21.  
  22. rm -rf $tmpdir
  23.  
  24. cat orphaned-branches.txt
  25. echo "---------------------------------------------------------------"
  26. echo "Orphaned branches written to orphaned-branches.txt"
  27. echo "Edit this file to contain only branches you want to remove,"
  28. echo "then rerun $0 with the 'rm' argument to delete them"
Add Comment
Please, Sign In to add comment