[SOLVED] Git branches deleted from remote still appearing in local repositories
If you use git as the version control system for your software projects be it Drupal or non-Drupal projects then there is a very good chance for you to have tried deleting branches locally. It is not very often that you have to delete branches from the remote repository. However when people delete branches from remote repositories these branches would still show up in local repositories of the developers. Here is how you handle this.
SCENARIO:
Deleting old unused branches.
ISSUE:
Even after deleting a branch from the remote repo with
git push origin :branchname
and issuing "git pull", the branch was appearing in the output of a
git branch -r
issued from within the local repo.
Also, it was observed that such branches would not appear on newly cloned copies of the repo.
REASON:
This is because "git pull" does not remove remote tracking branches for branches deleted from remote repo.
SOLUTION:
To remove remote tracking branches for deleted branches, you need to issue:
git remote prune origin
If you just want to list such stale branches (and not remove them), use this:
git remote prune origin --dry-run
Example Output:
zyxware@zyxsoft007:~/public_html/nd7$ git remote prune origin
Pruning origin
URL: [email protected]:ex.git
* [pruned] origin/old_unused_branch1
* [pruned] origin/old_unused_branch2
* [pruned] origin/old_unused_branch3
* [pruned] origin/old_unused_branch4