Skip to content

Delete a local and a remote GIT branch

This quick article lets you know how to delete a local branch in git and also how to delete a remote branch in git.

Delete a Local GIT branch

We can delete a branch by calling the branch command and passing in the -d option, followed by the branch name.

$ git branch -d <branchname>

We can force-delete a branch -D. This command deletes the branch regardless of its push and merge status.

$ git branch -D <branchname>

Example

Run the following command to delete “demo”.

$ git branch -d demo
Deleted branch demo (was 7f8e749b).

We can verify that “demo” has been deleted by calling “git branch”. Only the master branch (or other branches if there are any) should be listed.

$ git branch
* master

Delete a Remote GIT branch

To delete a remote branch, we do not use the “git branch” command – but instead “git push” with the “–delete” flag:

 $ git push origin --delete feature/login

You can also use the below command to delete a remote branch.

 $ git push <remote_name> :<branch_name>

Delete both Local and Remote GIT branch

Local and remote branches are completely separate objects in Git. Deleting one doesn’t mean the other would be deleted too. If you want any branch to be deleted, you need to delete it explicitly.

Leave a Reply

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.