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

Re: How to use @{-1} with push?

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Mar 28, 2016, 14:53 UTC
Message-ID
<CAHd499A-8iajchG7hUMKNnCN9riarU4G3S-HZxXusOdewwaVCg@mail.gmail.com>
In-Reply-To
<xmqqoaa22xmg.fsf@gitster.mtv.corp.google.com>
On Fri, Mar 25, 2016 at 1:58 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
> I thought these are clear from their documentation.  "push" works on
> refnames, "branch" works on branch names.  "push" takes an branch
> name as a short-hand and adds refs/heads/ when it makes sense, but
> because it does not make any sense for "git branch" to create a
> "branch" in a random place in refs/ (e.g. "refs/tags/foo" is not a
> branch), it takes "foo" (i.e. the name of the branch, whose
> underlying ref is "refs/heads/foo").
>
> So
>
>         ref=$(git rev-parse --symbolic-full-name "$2") &&
>         case "$ref" in
>         '') echo >&2 "No such thing $2"; exit 1 ;;
>         refs/heads/*) ref=${ref#refs/heads/} ;;
>         *) echo >&2 "That's not a branch $2"; exit 2 ;;
>         esac &&
>         git push "$1" "refs/heads/$ref" &&
>         git branch -D "$ref"
>
> or something?

Reading the git documentation feels a lot like reading the C++ standard. Not the best place to go to learn something. Some of the terminology is very detail-oriented. For example, until you explained the differences between push & branch, I always thought "ref" and "branch" were interchangeable. But now it's clear to me that a branch is just a type of ref, but refs are not branches. Also as a Windows developer, I am not as well-versed in bash scripting as I'd like to be.

So thanks for your explanation, it is clear now.
Previous: Junio C Hamano
Message 6 of 6 in “How to use @{-1} with push?”
  1. Robert DaileyMar 25, 2016
  2. Junio C HamanoMar 25, 2016
  3. Robert DaileyMar 25, 2016
  4. Robert DaileyMar 25, 2016
  5. Junio C HamanoMar 25, 2016
  6. Robert DaileyMar 28, 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.