* Notation for current branch? @ 2016-08-28 9:58 ryenus 2016-08-28 10:51 ` Kevin Daudt 0 siblings, 1 reply; 9+ messages in thread From: ryenus @ 2016-08-28 9:58 UTC (permalink / raw) To: git I wonder if there's an easy to use notation to refer to the current branch? which is expected be friendly to scripting. For HEAD, there's @, which is short and concise. But for the current branch, it seems one has to either use a not so friendly plumbing command, or grep/parse the output of `git branch`, since the latter doesn't even has any option to only print the plain name of the current branch, or maybe an option can be added to `git branch`? Thoughts? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-28 9:58 Notation for current branch? ryenus @ 2016-08-28 10:51 ` Kevin Daudt 2016-08-28 13:56 ` Jakub Narębski 0 siblings, 1 reply; 9+ messages in thread From: Kevin Daudt @ 2016-08-28 10:51 UTC (permalink / raw) To: ryenus; +Cc: git On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote: > I wonder if there's an easy to use notation to refer to the current branch? > which is expected be friendly to scripting. > > For HEAD, there's @, which is short and concise. > > But for the current branch, it seems one has to either use a not so friendly > plumbing command, or grep/parse the output of `git branch`, since the latter > doesn't even has any option to only print the plain name of the current branch, > or maybe an option can be added to `git branch`? > > Thoughts? Scripts should always rely on plubming commands, never on porcelain, as their output will change, and thus, break scripts. To get the current branch name, the best is to use `git rev-parse --symbolic-full-name`[1], which either returns you the current branch name (eg refs/heads/master), or HEAD, when you have a detached HEAD. If you only want the friendly name, add --abbrev-ref, which would then return master. [1]: git symbolic-ref HEAD would also work, but errors out when you're not on a branch. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-28 10:51 ` Kevin Daudt @ 2016-08-28 13:56 ` Jakub Narębski 2016-08-29 6:39 ` Jacob Keller 0 siblings, 1 reply; 9+ messages in thread From: Jakub Narębski @ 2016-08-28 13:56 UTC (permalink / raw) To: Kevin Daudt, ryenus; +Cc: git W dniu 28.08.2016 o 12:51, Kevin Daudt pisze: > On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote: >> I wonder if there's an easy to use notation to refer to the current branch? >> which is expected be friendly to scripting. >> >> For HEAD, there's @, which is short and concise. What's wrong with simply using 'HEAD' for scripting? >> >> But for the current branch, it seems one has to either use a not so friendly >> plumbing command, or grep/parse the output of `git branch`, since the latter >> doesn't even has any option to only print the plain name of the current branch, >> or maybe an option can be added to `git branch`? > > Scripts should always rely on plubming commands, never on porcelain, as > their output will change, and thus, break scripts. It is not something theoretical; the output of "git branch" for detached HEAD (aka anonymous / unnamed branch) did change. > To get the current branch name, the best is to use `git rev-parse > --symbolic-full-name`[1], which either returns you the current branch name > (eg refs/heads/master), or HEAD, when you have a detached HEAD. If you > only want the friendly name, add --abbrev-ref, which would then return > master. > > [1]: git symbolic-ref HEAD would also work, but errors out when you're > not on a branch. Note that in some cases current branch is implied, like e.g. in "@{<n>}" notation. -- Jakub Narębski ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-28 13:56 ` Jakub Narębski @ 2016-08-29 6:39 ` Jacob Keller 2016-08-29 19:49 ` Junio C Hamano 0 siblings, 1 reply; 9+ messages in thread From: Jacob Keller @ 2016-08-29 6:39 UTC (permalink / raw) To: Jakub Narębski; +Cc: Kevin Daudt, ryenus, Git mailing list On Sun, Aug 28, 2016 at 6:56 AM, Jakub Narębski <jnareb@gmail.com> wrote: > W dniu 28.08.2016 o 12:51, Kevin Daudt pisze: >> On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote: > >>> I wonder if there's an easy to use notation to refer to the current branch? >>> which is expected be friendly to scripting. >>> >>> For HEAD, there's @, which is short and concise. > > What's wrong with simply using 'HEAD' for scripting? > When you want to display the current branch to the user, e.g. when scripting a shell prompt or similar use Thanks, Jake ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-29 6:39 ` Jacob Keller @ 2016-08-29 19:49 ` Junio C Hamano 2016-08-29 19:52 ` Jacob Keller 2016-08-30 18:09 ` ryenus 0 siblings, 2 replies; 9+ messages in thread From: Junio C Hamano @ 2016-08-29 19:49 UTC (permalink / raw) To: Jacob Keller; +Cc: Jakub Narębski, Kevin Daudt, ryenus, Git mailing list Jacob Keller <jacob.keller@gmail.com> writes: >> What's wrong with simply using 'HEAD' for scripting? > > When you want to display the current branch to the user, e.g. when > scripting a shell prompt or similar use Wait. Even if a hypothetical version of Git understood @@ as "the current branch", how would you use that notation, instead of HEAD, to decide what to "display the current branch to the user"? You obviously will not be doing echo @@ You would be doing something around "git symbolic-ref" at the very least, and wouldn't you be feeding HEAD to that symbolic-ref anyway while doing so? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-29 19:49 ` Junio C Hamano @ 2016-08-29 19:52 ` Jacob Keller 2016-09-01 15:51 ` ryenus 2016-08-30 18:09 ` ryenus 1 sibling, 1 reply; 9+ messages in thread From: Jacob Keller @ 2016-08-29 19:52 UTC (permalink / raw) To: Junio C Hamano; +Cc: Jakub Narębski, Kevin Daudt, ryenus, Git mailing list On Mon, Aug 29, 2016 at 12:49 PM, Junio C Hamano <gitster@pobox.com> wrote: > Jacob Keller <jacob.keller@gmail.com> writes: > >>> What's wrong with simply using 'HEAD' for scripting? >> >> When you want to display the current branch to the user, e.g. when >> scripting a shell prompt or similar use > > Wait. Even if a hypothetical version of Git understood @@ as "the > current branch", how would you use that notation, instead of HEAD, > to decide what to "display the current branch to the user"? > > You obviously will not be doing > > echo @@ > > You would be doing something around "git symbolic-ref" at the very > least, and wouldn't you be feeding HEAD to that symbolic-ref anyway > while doing so? > Hmm. You are right, I mis-understood the original question. Use of "git symbolic-ref" seems like the right thing if you need to obtain the current branch name, and there's no reason to not just use HEAD there. Thanks, Jake ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-29 19:52 ` Jacob Keller @ 2016-09-01 15:51 ` ryenus 0 siblings, 0 replies; 9+ messages in thread From: ryenus @ 2016-09-01 15:51 UTC (permalink / raw) To: Jacob Keller Cc: Junio C Hamano, Jakub Narębski, Kevin Daudt, Git mailing list > Jacob Keller <jacob.keller@gmail.com> writes: > "git symbolic-ref" seems like the right thing if you need to obtain > the current branch name, and there's no reason to not just use HEAD > there. Really? Any reason why `git rev-parse --abbrev-ref '@{-1}'` works, but not `git symbolic-ref '@{-1}'`, or even `git symbolic-ref @`? BTW, possible to make the curly brances optional in `@{n}`, `@{-n}`, and the alike? coz they require quoting/escaping, and more typing :( ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-29 19:49 ` Junio C Hamano 2016-08-29 19:52 ` Jacob Keller @ 2016-08-30 18:09 ` ryenus 2016-08-30 18:19 ` Junio C Hamano 1 sibling, 1 reply; 9+ messages in thread From: ryenus @ 2016-08-30 18:09 UTC (permalink / raw) To: Junio C Hamano Cc: Jacob Keller, Jakub Narębski, Kevin Daudt, Git mailing list On 30 August 2016 at 03:49, Junio C Hamano <gitster@pobox.com> wrote: > Jacob Keller <jacob.keller@gmail.com> writes: > >>> What's wrong with simply using 'HEAD' for scripting? >> >> When you want to display the current branch to the user, e.g. when >> scripting a shell prompt or similar use > > Wait. Even if a hypothetical version of Git understood @@ as "the > current branch", how would you use that notation, instead of HEAD, > to decide what to "display the current branch to the user"? > > You obviously will not be doing > > echo @@ > > You would be doing something around "git symbolic-ref" at the very > least, and wouldn't you be feeding HEAD to that symbolic-ref anyway > while doing so? > For now the best use case I can think of is with git-reflog, e.g., the meaning of `git reflog HEAD` and `git reflog feature-branch` are quite different, even if I'm currently on the feature-branch, especially when I want to track the rebase histories (if any). If there's a notation for the current branch then I don't have to find the name of the current branch, then copy/paste it. However, in this case, maybe git-reflog can have a `-b` option to show the reflog of the current branch (if on any)? - ryenus ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Notation for current branch? 2016-08-30 18:09 ` ryenus @ 2016-08-30 18:19 ` Junio C Hamano 0 siblings, 0 replies; 9+ messages in thread From: Junio C Hamano @ 2016-08-30 18:19 UTC (permalink / raw) To: ryenus; +Cc: Jacob Keller, Jakub Narębski, Kevin Daudt, Git mailing list ryenus <ryenus@gmail.com> writes: > For now the best use case I can think of is with git-reflog, e.g., > the meaning of `git reflog HEAD` and `git reflog feature-branch` > are quite different, even if I'm currently on the feature-branch, > especially when I want to track the rebase histories (if any). "git reflog" gives you the reflog of HEAD in numbered format (HEAD@{1}, HEAD@{2}, etc.), and "git reflog HEAD@{now}" is an interesting way to tell it "I want that same HEAD reflog but not in numbered but in timed format). "git reflog @{0}" and "git reflog @{now}" give you the reflog of the current branch in these formats. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-09-01 15:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-08-28 9:58 Notation for current branch? ryenus 2016-08-28 10:51 ` Kevin Daudt 2016-08-28 13:56 ` Jakub Narębski 2016-08-29 6:39 ` Jacob Keller 2016-08-29 19:49 ` Junio C Hamano 2016-08-29 19:52 ` Jacob Keller 2016-09-01 15:51 ` ryenus 2016-08-30 18:09 ` ryenus 2016-08-30 18:19 ` Junio C Hamano
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.