To delete a Git branch locally, follow these steps:
Make sure you are on a branch other than the one you want to delete. You cannot delete the branch you are currently on.
Run the command 'git branch -d <branch-name>' to delete the local branch. Replace <branch-name> with the name of the branch you want to delete.
For example, to delete a branch named "my-feature-branch", you would run the following command:
git checkout master
git branch -d my-feature-branch
To delete a Git branch remotely, follow these steps:
Run the command 'git push <remote-name> --delete <branch-name>' to delete the remote branch. Replace <remote-name> with the name of the remote repository, and <branch-name> with the name of the branch you want to delete.
For example, if your remote repository is named "origin" and you want to delete a branch named "my-feature-branch", you would run the following command:
git push origin --delete my-feature-branch
Note that deleting a branch will permanently remove all of its associated commits and cannot be undone.
Comments (0)