new


Git Tutorial How do I Delete A Git Branch Locally And Remotely

In Git we occasionally have to delete a branch & we want to do this both locally & remotely. This page descripbes how we delete a git branch locally & remotely.


Delete a remote branch

Terminal example:
Terminal
>
git push origin -d branchName
> Output:

- [deleted] branchName

Delete a local branch

Terminal example:
Terminal
>
git branch -D branchName
> Output:

Deleted branch branchName (was a5f2b57).

When we delete a branch ensure that we are not on that branch so just checkout a different branch.
We have 3 different branches that are involved. We have:
  • the local branch
  • The remote origin branch
  • The local remote-tracking branch

To delete the remote branch we need to utilize the "push origin" so it will be "git push origin --delete branchName"
Here is the official Git documentation for Branch Management.
Here is the official Git documentation for Remote Branches.