Skip to content

Instantly share code, notes, and snippets.

@aliharis
Created January 21, 2024 09:10
Show Gist options
  • Save aliharis/41b6968ef1f04081b6020f3a6bc0d94e to your computer and use it in GitHub Desktop.
Save aliharis/41b6968ef1f04081b6020f3a6bc0d94e to your computer and use it in GitHub Desktop.
Delete stale branches on your machine
#!/bin/bash
# Update the local repository and prune remote-tracking branches
git fetch --prune
# Loop over each local branch and check if it has a remote tracking branch
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do
echo "Deleting local branch: $branch"
git branch -d "$branch"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment