git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git push origin BRANCHNAME question

From
Jeff King <peff@peff.net>
Date
Aug 25, 2016, 18:39 UTC
Message-ID
<20160825183928.jm7pihc4kzwuej6y@sigill.intra.peff.net>
In-Reply-To
<xmqqr39cn3fk.fsf@gitster.mtv.corp.google.com>
On Thu, Aug 25, 2016 at 10:50:23AM -0700, Junio C Hamano wrote:
Show 30 quoted lines
> Ed Greenberg <edg@greenberg.org> writes:
> 
> > I think I understand this from the git-push man page, but I want to
> > make sure:
> >
> > I have two branches, master and develop.
> >
> > If I am (accidentally) sitting on master, and issue 'git push origin
> > develop', does this properly push develop to remote develop, or does
> > it push master to remote develop (which seems to be bad, in the most
> > common use case.)  ?
> 
> You can find it out yourself quite easily, I would think.
> 
> $ git init src
> $ git init dst
> $ cd src
> $ git commit --allow-empty -m initial
> $ git checkout -b develop
> $ git commit --allow-empty -m second
> 
> $ git checkout master
> $ git push ../dst develop
> Counting objects: 3, done.
> Delta compression using up to 6 threads.
> Compressing objects: 100% (2/2), done.
> Writing objects: 100% (3/3), 226 bytes | 0 bytes/s, done.
> Total 3 (delta 1), reused 0 (delta 0)
> To ../dst
>  * [new branch]      develop -> develop
Yes, though I think the "why" is interesting here, too.

And the answer is that "develop" is a shortened refspec, whose full form is more like "develop:develop". A name with no colon is always the local source, and the implied destination is usually the same name on the remote (though it can be changed via config). The third paragraph of "<refspec>..." under OPTIONS in "git help push" covers this, though I do think it is a little hard to follow.

-Peff
Previous: Junio C Hamano
Message 3 of 3 in “git push origin BRANCHNAME question”
  1. Ed GreenbergAug 25, 2016
  2. Junio C HamanoAug 25, 2016
  3. Jeff KingAug 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.