git delete local branches which are not on remote code example

Example 1: delete local branches not on remote

git branch -vv | grep ': gone]'|  grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D

Example 2: git delete branches that aren't on remote

git fetch --all --prune

Example 3: git delete remote branches in local git

# Fetch changes from all remotes and locally delete 
# remote deleted branches/tags etc
# --prune will do the job :-;
git fetch --all --prune

Example 4: How to Delete Local/Remote Git Branches

$ git branch -a

# *master
# b1
# remote/origin/master
# remote/origin/b1

$ git push origin --delete b1
# [...]
# - [deleted] b1