Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created January 4, 2017 21:08
Show Gist options
  • Save camsaul/5f192adf2429bb62a6409cd56917654c to your computer and use it in GitHub Desktop.
Save camsaul/5f192adf2429bb62a6409cd56917654c to your computer and use it in GitHub Desktop.
Cleanup old branches in local git repo
#! /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