Remove locally cached GIT branches deleted on origin

Verma Varun
1 min readNov 6, 2020

Over time as you create pull requests and move your changes from temporary branches over to the dev or master branch, a lot of branches can pile up on your local system and can be noisy when you are trying to list all the branches.

If you’re using GitHub, it conveniently gives you the option to delete the temporary branch after merging into dev or master. But, the local git repository still shows the remote and local branches even though they have been deleted from GitHub. When branches get deleted on origin, your local repository won’t take notice of that. You’ll still have your locally cached versions of those branches (which is actually good) but git will still list them as remote branches.

List all branches (local and remote):

git branch -a

To remove the remote branches that have already been cleaned up on GitHub, you can use the prune command:

git fetch --prune

This would still leave your local branch intact that you probably won’t need. Delete the branch locally using this command:

git branch -d local_branch_name

--

--

Verma Varun

Mastering automation, improving efficiency and connecting systems.