You need to have your Git delete, from your Git repository, any remote-tracking name (such as origin/feature/tall
) that no longer has a corresponding branch name in the other Git repository over at origin
.
Remember that the way git clone
works is:
- copy all the commits from the other Git repository, but none of the branch names;
- have the other Git list out its branch names;
- create, in your own repository, a remote-tracking name for each branch name that they have;
- and finally, create one local branch name for your own use.
Subsequent git fetch
operations, including those run by git pull
, contact the other Git and read any branch names from the other Git repository, and use those to create or update your own Git repository's remote-tracking names. So if they add a feature/short
, you get an origin/feature/short
. But your Git does not delete your existing origin/feature/tall
merely because they've deleted their feature/tall
, by default. So after some time, you accumulate remote-tracking names for branch names that no longer exist.
To delete these, you must tell your own Git to do that. There are a number of ways to do this:
You can run git fetch --prune
. This has your Git ask their Git (their repository) about their branch names, and then removes from your repository any remote-tracking names that correspond to branch names that don't exist there now. Note that this does not affect any of your branch names. It only causes your own Git to remove stale remote-tracking names.
You can run git remote prune origin
. This is like git fetch --prune
except that it doesn't add or update remote-tracking names based on updated or new branch names on the remote, i.e., it does only the pruning step.
You can set fetch.prune
to true
in your Git configuration. If you do this, all git fetch
operations default to pruning.
I use the last of these myself. I think it should be the default, in Git, but it's not.