Git Prune

git prune to remove the unwanted branches from the local or the remote server. git prune removes the references of the branches we do not use anymore.   Usually, there are 3 kinds of branches that we need to clean up.

  • The local branches in which we do our day to day working.
  • The reference to the remote branches which we use for naming branches
  • The branches on the remote server
  To remove the unwanted branches from the local, run the command as in the following syntax.
git branch -D branch_name
To clean up the reference objects, run the command of the following syntax
git remote prune reference_name
To delete the unwanted remote branches, run the command
git push origin --delete branch-name
  Git prune comes in handy when it comes to keeping the repository neat and clean. Cleaning up the unwanted branches keeps the repository neat.]]>