To delete a Git branch locally, you can use the git branch command with the -d option, followed by the name of the branch you want to delete. For example:
git branch -d my-branch
This will delete the my-branch branch locally. If the branch has not been merged into the current branch, Git will refuse to delete it, and you will need to use the -D option instead of -d to force the deletion:
git branch -D my-branch
To delete a Git branch remotely, you can use the git push command with the --delete option, followed by the name of the remote repository and the name of the branch you want to delete. For example:
git push origin --delete my-branch
This will delete the my-branch branch from the origin remote repository.
If you want to delete the branch both locally and remotely, you can combine the two commands above:
git branch -d my-branch
git push origin --delete my-branch
This will delete the my-branch branch both locally and remotely.
It’s important to note that deleting a branch does not delete the commits associated with the branch. The commits are still available in the repository’s history and can be accessed through other branches or tags.
