To delete a Git branch locally and then remotely, you can follow these steps:
Delete the local branch using the
git branchcommand with the-doption:git branch -d <branch_name>This will delete the local branch named
<branch_name>. If the branch has unmerged changes, Git will not allow you to delete the branch. In that case, you can use the-Doption instead of-dto force delete the branch.Delete the remote branch using the
git pushcommand with the--deleteoption:git push origin --delete <branch_name>This will delete the remote branch named
<branch_name>on theoriginremote.
Note: If you don’t want to delete the remote branch, you can skip step 2.
If you’re using a different remote name, replace origin with the name of your remote. Once you have deleted the branch locally and remotely, it will no longer be available in your Git repository.
If you enjoyed this content, please consider sharing this link with a friend, following my GitHub, Twitter/X or LinkedIn accounts, or subscribing to my RSS feed.