Executive Summary
# Delete Remote branch $ git push <remote_name> -d <branch_name> # ..or alternatively.. $ git push <remote_name> :<branch_name> # Delete Local branch (use -D to force deletion if unmerged) $ git branch -d <branch_name>
Note that 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>
Executive Summary
$ git push -d <remote_name> <branchname>
$ git branch -d <branchname>
Note: In most cases, <remote_name>
will be origin
.
To delete the locallocal branch use one of the following:
$ git branch -d branch_name<branch_name>
$ git branch -D branch_name<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
]
Also note that git branch -d branch_name
will fail if you are currently
in the branch you want to remove. The message starts with
error: Cannot delete the branch 'branch_name'
. If so, first switch
to some other branch, for example: git checkout main
.
- The
-d
option is an alias for--delete
, which only deletes the branch if it has already been fully merged in its upstream branch. - The
-D
option is an alias for--delete --force
, which deletes the branch "irrespective of its merged status." [Source:man git-branch
] - You will receive an error if you try to delete the currently selected branch.
Delete Remote Branch [Updated on 8-Sep-2017]
Starting onwith Git v2.8.0, you can also use git push
with the -d
option as an alias for --delete
.
Therefore, the version of Git you have installed will dictate whether you need to use the easier or harder syntax.