In a Git repo how can I efficiently remove local tracking branches for deleted remote branches?
If I create a Github repo, then create a feature branch off master, then the Git cli shows this
user@workstation C:\Home\Development\Workspaces\Scratch\GitTest1
$ git branch -vv
* feature1 e1f5c4e [origin/feature1] Stuff added on branch feature1
master d7a1ee8 [origin/master] Initial commit
user@workstation C:\Home\Development\Workspaces\Scratch\GitTest1
$ git branch -a
* feature1
master
remotes/origin/feature1
remotes/origin/master
I can see what remote branches my local branches are tracking and everything is good.
If I delete the feature branch from Github and fetch --prune
.
user@workstation C:\Home\Development\Workspaces\Scratch\GitTest1
$ git fetch --prune
From https://github.com/Neutrino-Sunset/git-test
- [deleted] (none) -> origin/feature1
But now git branch -vv
still shows the deleted remote branch, even though git branch -a
no longer lists it.
user@workstation C:\Home\Development\Workspaces\Scratch\GitTest1
$ git branch -vv
* feature1 e1f5c4e [origin/feature1: gone] Stuff added on branch feature1
master d7a1ee8 [origin/master] Initial commit
user@workstation C:\Home\Development\Workspaces\Scratch\GitTest1
$ git branch -a
* feature1
master
remotes/origin/master
Because of this the only way I have to keep my local repository synchronised with my remote is to run git branch -vv
in one console, git branch -a
in another console. Then manually compare which of my local branches that say they are tracking a remote branch are actually tracking a branch that doesn't even exist, and then in a third console manually delete the extraneous branches.
For a large repo it's astonishingly cumbersome, and very easy to make a mistake.
Does Git really not provide a more intelligent way to do this?