Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Last active October 24, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/63c9962d1e171a81926496201cbec5b3 to your computer and use it in GitHub Desktop.
Save topherPedersen/63c9962d1e171a81926496201cbec5b3 to your computer and use it in GitHub Desktop.
Delete Old Git Branches on Mac using Zsh Shell Script
#!/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