Skip to content

Instantly share code, notes, and snippets.

@idan
Created September 18, 2021 18:54
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 idan/f9543c9068c5caf9622d6d8efadb4c2c to your computer and use it in GitHub Desktop.
Save idan/f9543c9068c5caf9622d6d8efadb4c2c to your computer and use it in GitHub Desktop.
A fish function which deletes all branches not called main or master
function branchclean
# delete branches that are not called 'main' or 'master'
# Invoke with -r to also delete the branches on the origin remote
# WARNING — this doesn't check if the branches are merged.
argparse 'r/remote' -- $argv
for b in (git branch | grep -v "^\*\?\s\+\(master\|main\)\$" | string trim);
git branch --delete $b;
if test -n "$_flag_r"
git push -d origin $b
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment