From the man page:
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>".
So I removed a bunch of branches using
git push origin :staleStuff
and then ran
git remote prune origin
However, only one single local branch was pruned. Some of these branches were created by me, some by co-workers. Does this indicate that I wasn’t tracking those branches correctly in the first place?
When you use
git push origin :staleStuff, it automatically removesorigin/staleStuff, so when you rangit remote prune origin, you have pruned some branch that was removed by someone else. It’s more likely that your co-workers now need to rungit pruneto get rid of branches you have removed.So what exactly
git remote prunedoes? Main idea: local branches (not tracking branches) are not touched bygit remote prunecommand and should be removed manually.Now, a real-world example for better understanding:
You have a remote repository with 2 branches:
masterandfeature. Let’s assume that you are working on both branches, so as a result you have these references in your local repository (full reference names are given to avoid any confusion):refs/heads/master(short namemaster)refs/heads/feature(short namefeature)refs/remotes/origin/master(short nameorigin/master)refs/remotes/origin/feature(short nameorigin/feature)Now, a typical scenario:
feature, merges it intomasterand removesfeaturebranch from remote repository.git fetch(orgit pull), no references are removed from your local repository, so you still have all those 4 references.git remote prune origin.featurebranch no longer exists, sorefs/remotes/origin/featureis a stale branch which should be removed.refs/heads/feature, becausegit remote prunedoes not remove anyrefs/heads/*references.It is possible to identify local branches, associated with remote tracking branches, by
branch.<branch_name>.mergeconfiguration parameter. This parameter is not really required for anything to work (probably exceptgit pull), so it might be missing.(updated with example & useful info from comments)