From 553a095288f184a09287d65632dce8c0328f3a56 Mon Sep 17 00:00:00 2001 From: Adam Sherwood Date: Tue, 2 Apr 2024 10:59:31 +0200 Subject: [PATCH] Add command to prune (upstream gone). --- Custom-Commands-Compendium.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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