DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Git - Delete Branches

Before deleting any branch if you want to know your branches just run:

$ git branch -a
Enter fullscreen mode Exit fullscreen mode

The output will be like:

*master
 feature
 remote/origin/master
 remote/origin/feature
Enter fullscreen mode Exit fullscreen mode

Now;

Delete Local Branch

$ git branch -d <branch_name>
Enter fullscreen mode Exit fullscreen mode

-d flag is for "delete" as you may assume. In addition to that, the -d flag
only deletes the branch if it has already been fully merged in its upstream
branch. You can also use -D, which is for --delete --force, which deletes
the branch "irrespective of its merged status." Source: git-scm

Delete Remote Branch

# New version (Git 1.7.0 or newer)
$ git push -d <remote_name> <branch_name>

# Git versions older than 1.7.0
$ git push <remote_name>  :<branch_name>
Enter fullscreen mode Exit fullscreen mode

All done!

Discussion (0)