How can I list any local branches that appear (as per .git/config
) to be tracking remote branches that no longer exist? Remote branches are on GitHub in this case but I suspect their location has no relevance.
For example:
a
, b
, c
and d
.a
is tracking origin/a
and c
is tracking origin/c
.b
and d
are not tracking remote branches.origin/a
has been been merged back into master and was deleted during a repository clean-up; I no longer need to keep local branch a
.a
is checked out to the working tree, running git fetch
or git pull
results in the error Your configuration specifies to merge with the ref 'a' from the remote, but no such ref was fetched.
How would I produce the list containing only a
and any other local branches that appear to be tracking remote branches that no longer exist?
I would like to identify these so that I can delete obsolete local branches I no longer need.
The list should not include local branches b
or d
that are not tracking remote branches, and also not c
that is tracking origin/c
, which still exists.
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.
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