Created
January 4, 2017 21:08
-
-
Save camsaul/5f192adf2429bb62a6409cd56917654c to your computer and use it in GitHub Desktop.
Cleanup old branches in local 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
#! /bin/bash | |
# Switch back to master | |
git checkout master | |
# Delete all local branches besides master | |
for branch in `git branch | grep -v 'master'` | |
do | |
git branch -D $branch | |
done | |
# Delete all remote tracking branches besides origin/master | |
for branch in `git branch --remotes | grep -v 'origin/master'` | |
do | |
git branch --remotes -D $branch | |
done | |
# Now re-fetch all the remote tracking branches that still exist | |
git pull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment