Last active
November 5, 2018 10:53
-
-
Save boywijnmaalen/320bd1a72f9b4d78a29c to your computer and use it in GitHub Desktop.
Remove local branches except the master branch
This file contains 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
########### | |
# DRY-RUN # | |
########### | |
# make sure you are on develop; one cannot ever delete the current branch | |
$ git checkout develop | |
# get references | |
$ git fetch | |
# fast forward (not merge) the current branch | |
$ git pull origin HEAD | |
# list every local branch (except 'develop' & 'master') that has already been merged with the local develop | |
$ git branch --merged develop | grep -vE 'develop|master' | |
# list stale references (like branches, tags, unreachable commits, etc) | |
$ git remote prune origin --dry-run | |
########### | |
# EXECUTE # | |
########### | |
# make sure you are on develop; one cannot ever delete the current branch | |
$ git checkout develop | |
# get references | |
$ git fetch | |
# fast forward (not merge) the current branch | |
$ git pull origin HEAD | |
# delete every local branch (except 'develop' & 'master') that has already been merged with the local develop | |
$ git branch --merged develop | grep -vE 'develop|master' | xargs git branch -d | |
# delete all stale tracking branches. | |
$ git gc --prune=now | |
# de-reference stale references (like branches, tags, unreachable commits, etc) | |
$ git remote prune origin | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment