Created
May 21, 2012 13:44
-
-
Save venables/2762393 to your computer and use it in GitHub Desktop.
Clean up a git repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # This script will clean up your git repo by doing the following: | |
| # => Pull the latest master | |
| # => Perform a 'git remote prune origin' | |
| # => Delete all local branches that are fully merged into master | |
| # => Delete all remote branches that are fully merged into master (if the --remote option is passed) | |
| # This has to be run from master | |
| git checkout master | |
| read -p "Pull master (y/n)? " | |
| if [ "$REPLY" == "y" ] | |
| then | |
| # Pull the latest master | |
| git pull origin master | |
| fi | |
| # Update our list of remotes | |
| git fetch | |
| git remote prune origin | |
| # Remove local fully merged branches | |
| git branch --merged master | grep -v 'master$' | xargs git branch -d | |
| if [ "$1" == "--remote" ] | |
| then | |
| # Show remote fully merged branches | |
| echo "The following remote branches are fully merged and will be removed:" | |
| git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' | |
| read -p "Continue (y/n)? " | |
| if [ "$REPLY" == "y" ] | |
| then | |
| # Remove remote fully merged branches | |
| git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' | xargs -I% git push origin :% | |
| echo "Done!" | |
| say "Obsolete branches are removed" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment