Remove local git branches deleted remotely

Often, a git branch is deleted in github repo after merging it into main branch. However, such deleted branch may still exist in your local machine.

To show all the branches in your local machine, do the following

git branch -a        

And you may see something like

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/vennDiagram
  remotes/origin/master        

And the branches starting with `remotes/` are the local cache of remote branches.

To remove the branches whose linked remote branches have been deleted, run

git fetch -p        

and it will clean these branches.

To view or add a comment, sign in

More articles by Zhenguo Zhang

Insights from the community

Others also viewed

Explore topics