Last active
October 24, 2022 15:09
-
-
Save topherPedersen/63c9962d1e171a81926496201cbec5b3 to your computer and use it in GitHub Desktop.
Delete Old Git Branches on Mac using Zsh Shell Script
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
#!/bin/zsh | |
# Put this script in your git repo: /Users/yourusername/yourrepo/delete_old_branches.sh | |
# Create a text file called old_branches.txt, put this in your repo as well: /Users/yourusername/yourrepo/old_branches.txt | |
# In old_branches.txt, put the names of the branches you want to delete. 1 Branch name per line, no commas. | |
# Then run... | |
# cd /Users/yourusername/yourrepo | |
# chmod 755 delete_old_branches.sh | |
# git config --global --add safe.directory /Users/yourusername/yourrepo | |
# sudo ./delete_old_branches.sh | |
cat "old_branches.txt" | { cat ; echo ; } | | |
while read line; do | |
# If you want to delete these branches on the remote server as well, uncomment out the line below | |
# push origin --delete $line; | |
git branch -D $line; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment