Git does not delete the (local) remote-tracking branches automatically if the branch was deleted in the remote repository. Additionally, before V2.0.1 remote-tracking branches were in some cases not deleted when you removed the remote from your git config (see VonC's answer).
To delete stale remote-tracking branches (branches that were deleted in the remote repository) for one of your remote repositories, run
git remote prune <remote>
To cite the man page or git remote
:
prune
Deletes all stale tracking branches under <name>. These stale branches have
already been removed from the remote repository referenced by <name>,
but are still locally available in "remotes/<name>".
With --dry-run option, report what branches will be pruned, but do
not actually prune them.
However, from your question it seems you manually removed .git/refs/remotes/theoldremote
, so Git no longer knows about the remote repository that the remote-tracking branches belonged to. That's not how you're supposed to do it.
The normal way to remove a remote repository is to run
git remote rm <remote>
This will remove the remote from your .git/config
, and will delete the remote-tracking branches.
If you just delete the directory under .git/refs/remotes/
, the branches will remain behind. Then you will need to remove them manually:
git branch -rd <remote>/<branchname>
You need option -r
to delete a remote branch.