Reputation: 1084
The list of branches in Azure DevOps Server (2019, locally installed) correctly shows only three branches in all section cause all others have been merged and deleted:
Why does git branch -r
returns plenty of the old merged or deleted branches (via UI)? And how to fix the repo to only contain the shown branches from the Azure DevOps Server web interface?
Upvotes: 1
Views: 614
Reputation: 15621
When a branch is removed on the origin, local branches that track the branch are not removed. This is an explicit actions since there might still be work in there you haven't pushed yet. To clean up local branches that track a branch that no longer exists on the origin, you need to prune remote branches.
The git remote prune
command removes local remote tracking branches where the branch no longer exists on the remote.
Prune
Deletes stale references associated with <name>. By default, stale remote-tracking branches under <name> are deleted, but depending on global configuration and the configuration of the remote we might even prune local tags that haven’t been pushed there. Equivalent togit fetch --prune <name>
, except that no new references will be fetched.
Source: git documentation - prune
If you want to see the branches that would be removed running the prune command without actually removing them, add the --dry-run
option.
Example: git remote prune origin --dry-run
EDIT:
As torek commented:
You can also use
git fetch --prune
(abbreviatedgit fetch -p
) or setfetch.prune
totrue
.
The last one means you never have to rungit remote prune
orgit fetch -p
, at the cost of not being able to restore an accidentally-deleted server branch.
Upvotes: 5