Susan Potter
git:

How do I delete a branch in Git locally and globally?

To delete a Git branch locally and then remotely, you can follow these steps:

  1. Delete the local branch using the git branch command with the -d option:

    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 -D option instead of -d to force delete the branch.

  2. Delete the remote branch using the git push command with the --delete option:

    git push origin --delete <branch_name>
    

    This will delete the remote branch named <branch_name> on the origin remote.

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.