How to delete a Git branch locally and remotely

Hostnbit

Delete Remote Branch

$ git push -d <remote_name> <branch_name>
$ git branch -d <branch_name>

in most cases the remote name is origin. In such a case you’ll have to use the command like so.

$ git push -d origin <branch_name>

Delete Local Branch

$ git branch -d branch_name
$ git branch -D branch_name

Note: The -d option is an alias for –delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for –delete –force, which deletes the branch “irrespective of its merged status.” [Source: man git-branch]

Hostnbit

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu Title
Scroll to Top