How can I delete all my local branches if they are deleted from GIT repo. Is there any command for that ? . I dont want to it one by one by the command git branch -D/-d branch-name .
Remove information on branches that were deleted on origin
When branches get deleted on origin, your local repository won't take notice of that.
You'll still have your locally cached versions of those branches (which is actually good) but git branch -a will still list them as remote branches.
You can clean up that information locally like this:
git remote prune origin
Your local copies of deleted branches are not removed by this.
The same effect is achieved by using
git fetch --prune
You could also set that as a default.
Just for reference if someone looking in this page later
Quiet good amount of details on the same
DevConnect Page
Command which we can use for fully merged local branches is
git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs git branch -d
This will list merged branches, grep for lines that are not master, main, or dev, then delete each of these branches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With