Skip to content

Instantly share code, notes, and snippets.

@SamTobias
Created June 13, 2024 14:59
Show Gist options
  • Save SamTobias/bc4c4745773f98512483e0fa0c2469eb to your computer and use it in GitHub Desktop.
Save SamTobias/bc4c4745773f98512483e0fa0c2469eb to your computer and use it in GitHub Desktop.
Git - Delete merged branches from remote
git branch -r --merged master | grep -Ev "(^\*|master|main|develop)" | sed 's/origin\///' | xargs -n 1 git push --delete origin
@SamTobias
Copy link
Author

SamTobias commented Jun 13, 2024

  1. Before running this command, checkout to the branch that you want to compare all the branches
  2. Change "master" in the command to the current branch
  3. Add in grep the branches that you want to keep (master, main, develop, etc...)

(On Windows, you will need to run it in Git Bash or WSL)

Source: StackOverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment