That's reasonable. I have aliases for a lot of my more frequent tasks like this. It's irrational in this case so maybe I should just get over this β but I feel a little nervous about making aliases for anything I use infrequently in case I forget what the underlying execution is.
I second using an alias. If you forget the alias you set, you can do git config -l to list all config values, including aliases, and just scan through them.
Or, if you remember the alias name, you can do get config --get alias.alias-name to show what it's an alias of.
Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
One observation to be made is if you for some reason has another branch that has "main" as part of its name, this command would not delete it. Maybe grep -v "^\*\? *main$", but then its getting already too complicated... π
most of my local branches have a prefix. So when i needed to cleanup all the local branches except the prod ,i have an alias set as git_branch_delete="git branch | grep $@ | xargs git branch -D". So i just do git_branch_delete flip and deletes all branches starting with flip prefix
maybe an alias?
anyway , thanks for the tip!
That's reasonable. I have aliases for a lot of my more frequent tasks like this. It's irrational in this case so maybe I should just get over this β but I feel a little nervous about making aliases for anything I use infrequently in case I forget what the underlying execution is.
I second using an alias. If you forget the alias you set, you can do
git config -lto list all config values, including aliases, and just scan through them.Or, if you remember the alias name, you can do
get config --get alias.alias-nameto show what it's an alias of.thanks , I didn't know that... It's useful for more complicated aliases.
...because you currently remember it so well that you wrote a post for your own future reference? π
One observation to be made is if you for some reason has another branch that has "main" as part of its name, this command would not delete it. Maybe
grep -v "^\*\? *main$", but then its getting already too complicated... πmake an alias out of it which also protect master and dev branches,
and also try to delete them in safer way with -d instead of -D.
git branch --mergeddoesn't work well if your team uses GitHub squash commits to merge PRs: stackoverflow.com/a/19309568/771768I've had a lot of success with my script that:
most of my local branches have a prefix. So when i needed to cleanup all the local branches except the prod ,i have an alias set as
git_branch_delete="git branch | grep $@ | xargs git branch -D". So i just dogit_branch_delete flipand deletes all branches starting withflipprefixYou can create an alias function like this:
used:
git removeLocalsor if you want to account for master vs main
used:
git removeLocals mainI recommend not doing the second one as you may accidentally remove your local version of main/master due to a typo
You could also just make two aliases removeLocalsMain and removeLocalsMaster
Every time I successfully use
xargsI spend the next several hours thinking "whoa, I did anxargs". It somehow never gets old.Solid
xargs, good stuff.omg thanks :)
That's a great tip! Thanks!
i think instead of main
$(git_main_branch)should be helpfulNice. Just one thing; it only deletes local ones.
If you want to delete only branches that have been deleted remotely then
git fetch --pruneis an option