DEV Community

loading...

Git - Delete Branches

serhatteker profile image Serhat Teker Originally published at tech.serhatteker.com on ・1 min read

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

$ git branch -a

The output will be like:

*master
 feature
 remote/origin/master
 remote/origin/feature

Now;

Delete Local Branch

$ git branch -d <branch_name>

-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>

All done!

Discussion (0)

pic
Editor guide