Skip to content

Instantly share code, notes, and snippets.

@stand-sure
Created July 14, 2022 12:29
Show Gist options
  • Save stand-sure/5d160e8932321619ae3e249d8d754d40 to your computer and use it in GitHub Desktop.
Save stand-sure/5d160e8932321619ae3e249d8d754d40 to your computer and use it in GitHub Desktop.
Git delete merged branches
#! /bin/bash
branchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout "$branchName" \
| git branch --merged \
| grep -E --invert-match "(^\*|master|main|dev)" \
| xargs git branch --delete \
&& git remote prune origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment