Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git Delete merged branches

Git delete merged branches

LOCALLY

git branch --merged | egrep -v "(master|development)" | xargs -n 1 git branch -d

Dry run

git branch --merged | egrep -v "(master|development)" | xargs -n 1 echo

REMOTELY

git branch -r --merged | egrep -v "(master|development)"| grep origin | sed 's/origin\///' | xargs -n 1 git push --delete origin

Dry run

git branch -r --merged | egrep -v "(master|development)"| grep origin | sed 's/origin\///' | xargs -n 1 echo

Once you delete the branch from the remote, you can prune to get rid of remote tracking branches with:

git remote prune origin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.