JackieWillen
JackieWillen

Reputation: 739

why "git push git push origin local-branch :development" will delete remote development branch?

why "git push git push origin local-branch :development" will delete remote development branch?

jackiewillen  ~/Documents/work/  git push origin yrh-deskmonitor-20170905 :development
Enter passphrase for key '.ssh/id_rsa':
To ssh://git.dianpingoa.com/ed-f2e/gandalf-plus.git
 - [deleted]         development

i try "push origin local-branch:development" is ok!So problem is on the semicolon;with space before semicolon or not is different.Why?

Upvotes: 2

Views: 652

Answers (2)

Samvel Petrosov
Samvel Petrosov

Reputation: 7706

From the documentation of the git push:

git push origin :experimental
Find a ref that matches experimental in
the origin repository (e.g. refs/heads/experimental), and delete it.

Upvotes: 3

user3159253
user3159253

Reputation: 17455

The problem is the space between yrh-deskmonitor-20170905 :development

You've pushed yrh-deskmonitor-20170905 as is AND deleted development branch

Probably, you wished to run

git push origin yrh-deskmonitor-20170905:development

instead.

The syntax of git push is like this:

git push <target> <refspec1> <refspec2> <refspec3>

where all <refspec>s are independent from each other and each may be in the following forms:

  1. <branch-or-tag-name>
  2. <local-refname>:<remote-branch-name>
  3. :<branch-or-tag-name>
  4. various "hacks" when remote refs is specified with name starting with refs/....

    • case 1 is used to create branches in a remote repo directly corresponding to branches in the local repo. This is the most "natural" usage.
    • case 2 is for creating a branch in a remote repo with a name different from the local one (I suppose, your case)
    • case 3 is for deleting given branches in the remote repo.
    • case 4 allows to create unsigned tags, different remotes and other kind of hacks that can be described as "low-level".

Don't worry, you still can re-create development branch (almost) without a harm by issuing git push <target> yrh-deskmonitor-20170905:development

Upvotes: 3

Related Questions