If You Want to Delete a Branch

git
147 words

You've Already Deleted the Remote Branch

And want to delete the corresponding local branch and remove the reference information in your local repository.

Here are the specific steps:

  1. Switch to the branch you want to delete:

    git checkout <branch_name>
    // Or use, more recommended to use switch for switching branches
    git switch <branch_name>
  2. Delete the remote branch:

    git push origin --delete <branch_name>

    This command tells Git that you want to delete the branch named <branch_name> on the origin server.

  3. Delete the local branch:

    git branch -d <branch_name>

    This command will delete the local branch. If the branch hasn't been merged, you can use the -D option to force delete.

  4. Update your local repository to remove the deleted branch references from the remote repository:

    git fetch --prune origin

    The -prune option tells Git to remove all remote branch references that no longer exist in the remote repository.

The above are the steps to delete a local remote branch in a git repository.