diff --git a/Custom-Commands-Compendium.md b/Custom-Commands-Compendium.md index 8bff7de..d1ef9c3 100644 --- a/Custom-Commands-Compendium.md +++ b/Custom-Commands-Compendium.md @@ -147,6 +147,20 @@ customCommands: description: "prune local branches that have been merged to master" ``` +## Pruning branches no longer on the remote. + +Implementation inspiration [here on Stackoverflow](https://stackoverflow.com/a/33548037/2081835). Basically, delete all the branches displaying `(upstream gone)`. + +```yml +customCommands: + - key: "G" + command: | + git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done + context: "localBranches" + description: "Prune local branches no longer on its remote; (G)one." + loadingText: "Pruning gone..." +``` + ## committing via [Commitizen](https://commitizen-tools.github.io/commitizen/) (`cz c`) ```yml