Cleanup and Delete Branches After a Pull Request

InstructorChris Achard

Share this video with your friends

Send Tweet

We've made a pull request and now we can clean up the branches by deleting the feature branch.

Branches are just pointers to commits - so we can safely delete branches without losing the underlying commits (once the commits are merged back into master).

So we'll use the github interface to delete the branch remotely, and to delete it locally we'll use git remote prune origin --dry-run and then git remote prune origin

That will tell us that the remote is gone, and we can finally clean up the feature branch with: git branch -d feature-branch

Andrey Kondakov
~ 4 years ago

And if we do not delete branches locally for some time. Is there any method to locally delete all branches that are not on github?

Will Johnson
~ 4 years ago

And if we do not delete branches locally for some time. Is there any method to locally delete all branches that are not on github?

Hey Andrey you can use git branch | grep -v "master" | xargs git branch -D to delete all branches locally