I guess, all popular Git repositories allow you to delete source branch when the PR with this branch is accepted. But sometimes you forget to use this option and end up with hundreds or thousands of stale branches across dozens of projects.
gitclean to the resque!
Prepare a list of repositories that you want to clean up. It does not matter what Git service is used (GitHub, GitLab, Bitbucket or something else), all you need is push access. List should look like this, one repo URL per line:
Now clone this repo and build it (
Unzip or untar a resulting distribution and run the tool with a single argument — path to the file with a list of repos:
gitclean will iterate through that list, clone each repo in a temporary folder and delete branches that were already merged into
master (basically, branches from
git branch --remotes --merged master).
Here is some shell magic that will do the same thing for a single repo:
git branch --remotes --merged master | grep -v master | cut -d/ -f2- | xargs -n 1 git push --delete origin git branch --merged master | grep -v master | xargs -n 1 git branch -d