Git branch cleanup after pull request Feb 24 2018

After merging a pull request Github shows the option to remove the branch that was merged, but that only removes the branch from the remote Github repo.

If you display all your branches in local( git branch -a ) you'll still see that the removed branch still appear.

To verify which branches are ok to remove you use the command:

git pull --prune --dry-run

This will show you which branches on remote can be removed, we will use this list to clean our local repo. The --dry-run flag makes the command just display what will happen if we prune the remote repo.

So now that we have the list we can remove the local branches:

git branch -d branch_x_ready_to_be_deleted

this will show you a warning that displays the branch can't be deleted because it hasn't been merged to master, once you are sure that is safe to delete that branch replace the -d flag with -D to force the delete.

git branch -D branch_x_ready_to_be_deleted

Now you can run the prune command:

git pull --prune

And that's it a clean local repo.

** If you want to check what else I'm currently doing be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message you can send it to