Remove remote branch info locally from git

You use git for version control.

You got a new feature to write.

You do the work and push your work into a new feature branch.

Open a PR for your work either on bitbucket or github or anything else.

PR gets merged and the remote branch is deleted.

But, wait, you have the remote repository still listing locally when you run:

git branch -r

Now, I don’t want it. Once the branch has been disposed of remotely, it has no business on the local machine.

So….there are two ways to get rid of it.

1. Remove all remote branches deleted remotely with this command:

git remote update origin --prune

2. Remove just one branch locally:

git remote prune my-new-feature

There is however a subtle difference in the two, i.e. you can pass options to the latter command to execute a dry run before actually doing it, like the command below:

git remote prune -n my-new-feature

Hope it helps!

About andhapp

Namastey (Hello) Stranger, This is not the geekiest blog on the planet yet it is not the dumbest one either. I am a small time developer who likes to explore new technologies. I usually program in Java, Groovy and Ruby and take keen interest in the surrounding geeky developments.
This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>