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:
1
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:
1
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.
1
git branch -D branch_x_ready_to_be_deleted
Now you can run the prune command:
1
git pull --prune
And that's it a clean local repo.