Guest User

Untitled

a guest
Jan 16th, 2019
89
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. for branch in $(git branch | cut -c 3-)
  4. do
  5. if [ $(git ls-tree $branch | wc -m) -eq 0 ]
  6. then
  7. echo "branch $branch is empty"
  8. fi
  9. done
  10.  
  11. ## this will treat $1 as a repository and go through it and delete all branches and tags with empty content.
  12.  
  13. export GIT_DIR=$1/.git
  14. export GIT_WORK_TREE=$1
  15.  
  16. echo Looking for empty branches in $1
  17. git branch | while read BRANCH
  18. do
  19. REALBRANCH=`echo "$BRANCH" | sed -e 's/*//g'`
  20. NOFILES=`git ls-tree $REALBRANCH | wc -l | tr -d ' '`
  21. # echo $NAME "$REALBRANCH" $NOFILES
  22. if [[ "$NOFILES" == "0" ]]
  23. then
  24. git branch -D $REALBRANCH
  25. fi
  26. done
  27.  
  28. git tag | while read BRANCH
  29. do
  30. REALBRANCH=`echo "$BRANCH" | sed -e 's/*//g'`
  31. NOFILES=`git ls-tree $REALBRANCH | wc -l | tr -d ' '`
  32. # echo $NAME "$REALBRANCH" $NOFILES
  33. if [[ "$NOFILES" == "0" ]]
  34. then
  35. git tag -d $REALBRANCH
  36. fi
  37. done
Add Comment
Please, Sign In to add comment