Git: How do I list local branches that are tracking remote branches that no longer exist?

If your local branches are tracking the remote branch you can filter the list of branches so show the ones that do not have a tracking branch with:

git branch -vv | grep -v origin

This will provide some extra information about the last commit that is on the branch but you can filter that out

git branch -vv | grep -v origin | awk '{print $1}'

This will only print the name of the branch that isn't tracking a remote branch.


git for-each-ref refs/heads --format='%(refname:short) %(upstream)' \
| awk 'NF==1'

will do it. NF is awk's "number of fields", and its default action is print.


LANG=en git branch --format='%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' | grep '.'

Tags:

Git