Created
January 21, 2024 09:10
-
-
Save aliharis/41b6968ef1f04081b6020f3a6bc0d94e to your computer and use it in GitHub Desktop.
Delete stale branches on your machine
This file contains 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
#!/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