Eliminated superfluous updates by others that simply added characters in body.
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159

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.

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>

To delete the local branch use one of the following:

$ 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]
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.

Delete Remote Branch [Updated on 8-Sep-2017]

Starting on 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.

Executive Summary

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

Note: In most cases, <remote_name> will be origin.

To delete the local branch use one of the following:

$ git branch -d <branch_name>
$ git branch -D <branch_name>
  • 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

Starting with 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.

Clarifying with comments the executive summary
Source Link
Basil Musa
  • 7k
  • 6
  • 54
  • 61

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

# 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>
added 18 characters in body
Source Link
Junaid
  • 3.7k
  • 1
  • 29
  • 33

Executive Summary

$ git push -d <remote_name> <branch_name>
$ 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> <branch_name>
$ 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> <branch_name>
$ 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> <branch_name>
$ 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>
Suggesting an explanation on what to do in case of `error: Cannot delete the branch 'branch_name'`.
Source Link
Loading
I added an example command that serves as an explicit example
Source Link
Bombe
  • 76.5k
  • 20
  • 118
  • 125
Loading
I added an example command that serves as an explicit example
Source Link
Loading
added 98 characters in body
Source Link
CodeWizard
  • 101.2k
  • 20
  • 116
  • 141
Loading
Since the other command already uses the shorthand `-d`, it seems biased to make the first one longer.
Source Link
Lazar Ljubenović
  • 16.6k
  • 8
  • 48
  • 82
Loading
added 2 characters in body
Source Link
Anant Kumar Singh
  • 67.1k
  • 10
  • 47
  • 89
Loading
The `-d` option only works for version 2.8.0. Most users are unlikely to have the latest version.. so its better to have `--delete` in the summary.
Source Link
Loading
Updated executive summary.
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
Added a note about using push origin -d (stated on the executive summary). The short version of --delete is only available since Git 2.8.0.
Source Link
Loading
In "Executive Summary", moved "-d" switch to after remote name; Added "--delete" switch which is only one available on git 1.9.
Source Link
Geoffrey
  • 5.2k
  • 8
  • 41
  • 74
Loading
Reorder -d in git push origin to make it more like the local delete command.
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
Use -d instead of --delete in exec summary
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
Keeping exec summary short
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
added forced delete to executive summary
Source Link
Vicky
  • 15.1k
  • 50
  • 128
  • 218
Loading
Rollback to Revision 20
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
minor edits on cmd
Source Link
Prashanth Sams
  • 14.3k
  • 16
  • 88
  • 113
Loading
changing order allows autocomplete on remote delete.
Source Link
Michael Cole
  • 13.9k
  • 4
  • 70
  • 84
Loading
Added Executive Summary to succinctly answer the question and then provide the details.
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading
Changed to reflect my intentions in answering the question.
Source Link
Matthew Rankin
  • 414.2k
  • 38
  • 117
  • 159
Loading