{"thread":{"id":"43947","subject":"Notation for current branch?","startedAt":"2016-08-28T09:58:44Z","lastAt":"2016-09-01T15:52:34Z","messageCount":9,"participants":["ryenus","Kevin Daudt","Jakub Narębski","Jacob Keller","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"300364","messageId":"CAKkAvazQxhtQauSb3MTVhzoK=xWbjMzQLBPQZUpp1n7VMUMJbQ@mail.gmail.com","threadId":"43947","inReplyTo":null,"subject":"Notation for current branch?","fromName":"ryenus","fromEmail":"ryenus@gmail.com","sentAt":"2016-08-28T09:58:18Z","receivedAt":"2016-08-28T09:58:44Z","isPatch":false,"sender":{"key":"ryenus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/610161?v=4"},"body":"I wonder if there's an easy to use notation to refer to the current branch?\nwhich is expected be friendly to scripting.\n\nFor HEAD, there's @, which is short and concise.\n\nBut for the current branch, it seems one has to either use a not so friendly\nplumbing command, or grep/parse the output of `git branch`, since the latter\ndoesn't even has any option to only print the plain name of the current branch,\nor maybe an option can be added to `git branch`?\n\nThoughts?\n"},{"id":"300365","messageId":"20160828105159.GA5477@ikke.info","threadId":"43947","inReplyTo":"CAKkAvazQxhtQauSb3MTVhzoK=xWbjMzQLBPQZUpp1n7VMUMJbQ@mail.gmail.com","subject":"Re: Notation for current branch?","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2016-08-28T10:51:59Z","receivedAt":"2016-08-28T10:52:30Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote:\n> I wonder if there's an easy to use notation to refer to the current branch?\n> which is expected be friendly to scripting.\n> \n> For HEAD, there's @, which is short and concise.\n> \n> But for the current branch, it seems one has to either use a not so friendly\n> plumbing command, or grep/parse the output of `git branch`, since the latter\n> doesn't even has any option to only print the plain name of the current branch,\n> or maybe an option can be added to `git branch`?\n> \n> Thoughts?\n\nScripts should always rely on plubming commands, never on porcelain, as\ntheir output will change, and thus, break scripts.\n\nTo get the current branch name, the best is to use `git rev-parse\n--symbolic-full-name`[1], which either returns you the current branch name\n(eg refs/heads/master), or HEAD, when you have a detached HEAD. If you\nonly want the friendly name, add --abbrev-ref, which would then return\nmaster.\n\n[1]: git symbolic-ref HEAD would also work, but errors out when you're\nnot on a branch.\n"},{"id":"300371","messageId":"4114ccbc-6b23-b7fe-ce4a-fcd0c9e4038a@gmail.com","threadId":"43947","inReplyTo":"20160828105159.GA5477@ikke.info","subject":"Re: Notation for current branch?","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-08-28T13:56:05Z","receivedAt":"2016-08-28T14:00:13Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 28.08.2016 o 12:51, Kevin Daudt pisze:\n> On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote:\n\n>> I wonder if there's an easy to use notation to refer to the current branch?\n>> which is expected be friendly to scripting.\n>>\n>> For HEAD, there's @, which is short and concise.\n\nWhat's wrong with simply using 'HEAD' for scripting?\n\n>>\n>> But for the current branch, it seems one has to either use a not so friendly\n>> plumbing command, or grep/parse the output of `git branch`, since the latter\n>> doesn't even has any option to only print the plain name of the current branch,\n>> or maybe an option can be added to `git branch`?\n> \n> Scripts should always rely on plubming commands, never on porcelain, as\n> their output will change, and thus, break scripts.\n\nIt is not something theoretical; the output of \"git branch\" for detached HEAD\n(aka anonymous / unnamed branch) did change.\n \n> To get the current branch name, the best is to use `git rev-parse\n> --symbolic-full-name`[1], which either returns you the current branch name\n> (eg refs/heads/master), or HEAD, when you have a detached HEAD. If you\n> only want the friendly name, add --abbrev-ref, which would then return\n> master.\n> \n> [1]: git symbolic-ref HEAD would also work, but errors out when you're\n> not on a branch.\n\nNote that in some cases current branch is implied, like e.g. in\n\"@{<n>}\" notation.\n\n-- \nJakub Narębski\n\n"},{"id":"300407","messageId":"CA+P7+xrGh687cYHJmYyXiWfjg_8i2-31FZOvk4bEMsO1FU22WA@mail.gmail.com","threadId":"43947","inReplyTo":"4114ccbc-6b23-b7fe-ce4a-fcd0c9e4038a@gmail.com","subject":"Re: Notation for current branch?","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-08-29T06:39:02Z","receivedAt":"2016-08-29T06:39:27Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Sun, Aug 28, 2016 at 6:56 AM, Jakub Narębski <jnareb@gmail.com> wrote:\n> W dniu 28.08.2016 o 12:51, Kevin Daudt pisze:\n>> On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote:\n>\n>>> I wonder if there's an easy to use notation to refer to the current branch?\n>>> which is expected be friendly to scripting.\n>>>\n>>> For HEAD, there's @, which is short and concise.\n>\n> What's wrong with simply using 'HEAD' for scripting?\n>\n\nWhen you want to display the current branch to the user, e.g. when\nscripting a shell prompt or similar use\n\nThanks,\nJake\n"},{"id":"300487","messageId":"xmqqy43f9wzh.fsf@gitster.mtv.corp.google.com","threadId":"43947","inReplyTo":"CA+P7+xrGh687cYHJmYyXiWfjg_8i2-31FZOvk4bEMsO1FU22WA@mail.gmail.com","subject":"Re: Notation for current branch?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-29T19:49:22Z","receivedAt":"2016-08-29T19:49:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n>> What's wrong with simply using 'HEAD' for scripting?\n>\n> When you want to display the current branch to the user, e.g. when\n> scripting a shell prompt or similar use\n\nWait.  Even if a hypothetical version of Git understood @@ as \"the\ncurrent branch\", how would you use that notation, instead of HEAD,\nto decide what to \"display the current branch to the user\"?\n\nYou obviously will not be doing\n\n\techo @@\n\nYou would be doing something around \"git symbolic-ref\" at the very\nleast, and wouldn't you be feeding HEAD to that symbolic-ref anyway\nwhile doing so?\n\n"},{"id":"300489","messageId":"CA+P7+xpz8UNt6bBgrJvsHdFE+MQ4J80K1ed+b41XH_CG6HYYTA@mail.gmail.com","threadId":"43947","inReplyTo":"xmqqy43f9wzh.fsf@gitster.mtv.corp.google.com","subject":"Re: Notation for current branch?","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2016-08-29T19:52:40Z","receivedAt":"2016-08-29T19:53:06Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Aug 29, 2016 at 12:49 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jacob Keller <jacob.keller@gmail.com> writes:\n>\n>>> What's wrong with simply using 'HEAD' for scripting?\n>>\n>> When you want to display the current branch to the user, e.g. when\n>> scripting a shell prompt or similar use\n>\n> Wait.  Even if a hypothetical version of Git understood @@ as \"the\n> current branch\", how would you use that notation, instead of HEAD,\n> to decide what to \"display the current branch to the user\"?\n>\n> You obviously will not be doing\n>\n>         echo @@\n>\n> You would be doing something around \"git symbolic-ref\" at the very\n> least, and wouldn't you be feeding HEAD to that symbolic-ref anyway\n> while doing so?\n>\n\nHmm. You are right, I mis-understood the original question. Use of\n\"git symbolic-ref\" seems like the right thing if you need to obtain\nthe current branch name, and there's no reason to not just use HEAD\nthere.\n\nThanks,\nJake\n"},{"id":"300588","messageId":"CAKkAvaxyEMjASzfGTqt73AtW7ag-YfqN1yVLEhFreiU-UVdnkA@mail.gmail.com","threadId":"43947","inReplyTo":"xmqqy43f9wzh.fsf@gitster.mtv.corp.google.com","subject":"Re: Notation for current branch?","fromName":"ryenus","fromEmail":"ryenus@gmail.com","sentAt":"2016-08-30T18:09:58Z","receivedAt":"2016-08-30T18:10:24Z","isPatch":false,"sender":{"key":"ryenus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/610161?v=4"},"body":"On 30 August 2016 at 03:49, Junio C Hamano <gitster@pobox.com> wrote:\n> Jacob Keller <jacob.keller@gmail.com> writes:\n>\n>>> What's wrong with simply using 'HEAD' for scripting?\n>>\n>> When you want to display the current branch to the user, e.g. when\n>> scripting a shell prompt or similar use\n>\n> Wait.  Even if a hypothetical version of Git understood @@ as \"the\n> current branch\", how would you use that notation, instead of HEAD,\n> to decide what to \"display the current branch to the user\"?\n>\n> You obviously will not be doing\n>\n>         echo @@\n>\n> You would be doing something around \"git symbolic-ref\" at the very\n> least, and wouldn't you be feeding HEAD to that symbolic-ref anyway\n> while doing so?\n>\n\nFor now the best use case I can think of is with git-reflog, e.g.,\nthe meaning of `git reflog HEAD` and `git reflog feature-branch`\nare quite different, even if I'm currently on the feature-branch,\nespecially when I want to track the rebase histories (if any).\n\nIf there's a notation for the current branch then I don't have to\nfind the name of the current branch, then copy/paste it.\nHowever, in this case, maybe git-reflog can have a `-b` option to\nshow the reflog of the current branch (if on any)?\n\n- ryenus\n"},{"id":"300591","messageId":"xmqqoa4a3yrl.fsf@gitster.mtv.corp.google.com","threadId":"43947","inReplyTo":"CAKkAvaxyEMjASzfGTqt73AtW7ag-YfqN1yVLEhFreiU-UVdnkA@mail.gmail.com","subject":"Re: Notation for current branch?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-30T18:19:42Z","receivedAt":"2016-08-30T18:19:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"ryenus <ryenus@gmail.com> writes:\n\n> For now the best use case I can think of is with git-reflog, e.g.,\n> the meaning of `git reflog HEAD` and `git reflog feature-branch`\n> are quite different, even if I'm currently on the feature-branch,\n> especially when I want to track the rebase histories (if any).\n\n\"git reflog\" gives you the reflog of HEAD in numbered format\n(HEAD@{1}, HEAD@{2}, etc.), and \"git reflog HEAD@{now}\" is an\ninteresting way to tell it \"I want that same HEAD reflog but not in\nnumbered but in timed format).\n\n\"git reflog @{0}\" and \"git reflog @{now}\" give you the reflog of the\ncurrent branch in these formats.\n\n"},{"id":"300811","messageId":"CAKkAvaxD75sC-S7QBG6gXYbSMmBz5hpe8ZEYRRUt_BE99yvrYg@mail.gmail.com","threadId":"43947","inReplyTo":"CA+P7+xpz8UNt6bBgrJvsHdFE+MQ4J80K1ed+b41XH_CG6HYYTA@mail.gmail.com","subject":"Re: Notation for current branch?","fromName":"ryenus","fromEmail":"ryenus@gmail.com","sentAt":"2016-09-01T15:51:55Z","receivedAt":"2016-09-01T15:52:34Z","isPatch":false,"sender":{"key":"ryenus@gmail.com","avatar":"https://avatars.githubusercontent.com/u/610161?v=4"},"body":"> Jacob Keller <jacob.keller@gmail.com> writes:\n> \"git symbolic-ref\" seems like the right thing if you need to obtain\n> the current branch name, and there's no reason to not just use HEAD\n> there.\n\nReally? Any reason why `git rev-parse --abbrev-ref '@{-1}'` works,\nbut not `git symbolic-ref '@{-1}'`, or even `git symbolic-ref @`?\n\nBTW, possible to make the curly brances optional in `@{n}`, `@{-n}`,\nand the alike? coz they require quoting/escaping, and more typing :(\n"}]}