Created
March 31, 2026 05:36
-
-
Save iamdadmin/825a09c5ee4ab051e12792c9f8021232 to your computer and use it in GitHub Desktop.
Gitclean - a simple shell script (aimed at macos paths but you can adapt for linux) to automate the pruning of deleted git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create the script and place it in ~/.local/bin/gitclean, setting it +x | |
| echo '#!/usr/bin/env bash | |
| # Update remote references | |
| git fetch --prune | |
| # Identify and delete local branches that no longer exist on remote | |
| git branch -vv | grep "gone]" | awk "{print \$1}" | xargs git branch -D | |
| ' > ~/.local/bin/gitclean && chmod +x ~/.local/bin/gitclean | |
| # Add the path to your $path | |
| echo 'export PATH="~/.local/bin:$PATH" >> .zshrc | |
| # Change the paths as you need! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment