Guest User

Untitled

a guest
Jan 19th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/bin/bash
  2. # git-cleanup-repo
  3. #
  4. # Author: Rob Miller <rob@bigfish.co.uk>
  5. # Adapted from the original by Yorick Sijsling
  6.  
  7. CLEANUP_REMOTE=${CLEANUP_REMOTE:-'no'}
  8.  
  9. git checkout master &> /dev/null
  10.  
  11. # Make sure we're working with the most up-to-date version of master.
  12. git fetch
  13.  
  14. # Prune obsolete remote tracking branches. These are branches that we
  15. # once tracked, but have since been deleted on the remote.
  16. git remote prune origin
  17.  
  18. # List all the branches that have been merged fully into master, and
  19. # then delete them. We use the remote master here, just in case our
  20. # local master is out of date.
  21. git branch --merged origin/master | grep -v 'master$' | xargs git branch -d
  22.  
  23. # Now the same, but including remote branches.
  24. MERGED_ON_REMOTE=`git branch -r --merged origin/master | sed 's/ *origin\///' | grep -v 'master$'`
  25.  
  26. if [[ "$CLEANUP_REMOTE" != 'no' && "$MERGED_ON_REMOTE" ]]; then
  27. echo "The following remote branches are fully merged and will be removed:"
  28. echo $MERGED_ON_REMOTE
  29.  
  30. read -p "Continue (y/N)? "
  31. if [ "$REPLY" == "y" ]; then
  32. git branch -r --merged origin/master | sed 's/ *origin\///' \
  33. | grep -v 'master$' | xargs -I% git push origin :% 2>&1 \
  34. | grep --colour=never 'deleted'
  35. echo "Done!"
  36. fi
  37. else
  38. echo "to cleanup remote branches, set env. variable CLEANUP_REMOTE=yes"
  39. fi
Add Comment
Please, Sign In to add comment