How to use git push prune to delete remote branches?

by coty_beier , in category: General Help , 2 months ago

How to use git push prune to delete remote branches?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brock , 2 months ago

@coty_beier 

To use git push prune to delete remote branches, follow these steps:

  1. First, ensure that you have the latest changes from the remote repository by running git fetch.
  2. Run git branch -r to view the list of remote branches. Identify the branches you want to delete.
  3. Use the git push command with the --prune or -p option, followed by the name of the remote repository, and the branches you want to delete. For example, to delete a remote branch named "feature-branch", use the following command: git push --prune origin feature-branch If you want to delete multiple branches, you can specify them separated by a space: git push --prune origin branch1 branch2 branch3
  4. Git will verify the branches to be deleted and ask for confirmation. Review the list and type "y" to confirm the deletion. remote: Pruning old remote branches... ... To


Note: Be cautious while using git push --prune as the deleted branches cannot be easily recovered. It is recommended to double-check the branch names before confirming the deletion.