git delete all remote branches code example

Example 1: git remove deleted remote branches

git fetch origin --prune

Example 2: git delete remote branch

#delete remote branch
git push -d <remote_name> <branch_name>
#example: git push -d origin new_feature

#delete local branch
git branch -d <branch_name>
#example: git branch -d new_feature

Example 3: remove all branches deleted on remote

# set this alias in git.config
git config --global alias.gone "! git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '\$2 == \"[gone]\" {print \$1}' | xargs -r git branch -D"
# then run
git gone

Example 4: Remove All Local Branches not on Remote

$ git branch -r | egrep -v -f /dev/fd/0  <(git branch -vv | grep origin) | xargs git branch -d