Skip to content

Instantly share code, notes, and snippets.

@davdenic
Last active April 1, 2021 20:23
Show Gist options
  • Save davdenic/dcf1a742b2b328bd10aed8f41d43f360 to your computer and use it in GitHub Desktop.
Save davdenic/dcf1a742b2b328bd10aed8f41d43f360 to your computer and use it in GitHub Desktop.
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