To clean all of your local branches except the current
staging, you can use this script:
git branch | grep -v "master\|staging" | xargs git branch -D
You can add more branches to the list of the ones that you want to skip, for example if you wanted to keep
dev branch in addition to the current branch, master and staging:
To further automate this, you can add an alias to your terminal by modifying your
... alias clean-branches="git branch | grep -v \"master\|staging\" | xargs git branch -D" ...
Now, when you're within the project directory, you can use
clean-branches command to perform this trimming automatically.