Using the command git branch -a
I see several remotes/origin/branchname
for remote branches which were deleted from the server already. Why this happens and how to refresh the list? Thank you.
3 回答
This is by design in git.
For each branch of each remote repository you use, git creates a local copy under remotes/<remote name>/
. These are called "remote-tracking branches".
If the original branch is deleted from the remote repository, git will not automatically delete your local remote-tracking branch. After all, you might still need it: Maybe you based a local branch on it, or maybe you intend to, or you still need it for reference...
So to be on the safe side, git will keep the branch. To get rid of it, you can either:
- delete it directly using
git branch -rd <remote name>/<branch name>
or - run
git remote prune origin
(or usegit fetch --prune
) to delete all remote-tracking branches that no longer exist in the remote
The advantage of git branch -rd
is that it also works off-line, while the second option needs access to the remote.
git fetch
normally only updates changed remote branches. If you add --prune
it will also remove all remote branches that no longer exist upstream.
you can remove obsolete remote branches with git origin prune
. you can see them because you tracking them in local branches