To delete a Git branch locally and then remotely, you can follow these steps:
Delete the local branch using the
git branchcommand with the
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
git push origin --delete <branch_name>
This will delete the remote branch named
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 via social media, following my accounts, or subscribing to the RSS feed.