3

Deleting a remote branch is done with:

git push origin :master

If the local is behind the remote it needs to be done with:

git push --force origin :master

But what does it mean to force a delete of e.g. master based on where the local master is pointing at? You will not be deleting where master is pointing to in the remote.

u123
  • 15,603
  • 58
  • 186
  • 303
  • 3
    Your question doesn't make any sense. Your syntax looks more like you are deleting your master branch than pushing from a local branch. – Andrew C Oct 19 '14 at 03:16

1 Answers1

3

The :branch refspec is the syntax for pushing a branch deletion, also written as:

git push origin --delete <branchName>

This isn't to be mixed up with git push :, where the ':' stand for "matching branch".

The --force is used for the case where a local branch has a different history than its remote counterpart (upstream branch).

For example, if you rebase master, its history would change and you would need --force to push it.


You will not be deleting where master is pointing to in the remote.

No, you will be deleting the branch itself (in the remote repo), not the commits of that branch in the remote repo.
if those commits are no longer referenced by any branch, they will become "invisible" (soft delete), but will still be accessible through a git reflog executed in that remote repo (on the remote server).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • "case where a local branch has a different history than its remote" - What local branch? This command doesn't seem to involve any local branch. – Chris Martin Oct 19 '14 at 08:34
  • @ChrisMartin that last comment was about a regular push. Since the OP's command doesn't involve a local branch, the `--force` makes less sense. – VonC Oct 19 '14 at 09:51