Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean the branches in git repository according to the remote
#!/bin/bash
# Usage: ./git_clean_branches.sh REPOSITORY_PATH
# Go to the directory
cd "$1"
# Delete branches, but keep develop, master and the current branch
git remote prune origin
git branch --merged | grep -v "\*" | grep -v "master" | grep -v "develop" | xargs -n 1 git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment