Skip to content

Instantly share code, notes, and snippets.

@iamdadmin
Created March 31, 2026 05:36
Show Gist options
  • Select an option

  • Save iamdadmin/825a09c5ee4ab051e12792c9f8021232 to your computer and use it in GitHub Desktop.

Select an option

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
# 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