{"thread":{"id":"38601","subject":"Git Feature Request - show current branch","startedAt":"2015-02-19T13:14:33Z","lastAt":"2015-02-20T10:16:39Z","messageCount":5,"participants":["mdconf@seznam.cz","Randall S. Becker","Michael J Gruber","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"256347","messageId":"13b.3lxh{.41MsIT3sthY.1KvU6v@seznam.cz","threadId":"38601","inReplyTo":null,"subject":"Git Feature Request - show current branch","fromName":"","fromEmail":"mdconf@seznam.cz","sentAt":"2015-02-19T13:14:33Z","receivedAt":"2015-02-19T13:14:33Z","isPatch":false,"sender":{"key":"mdconf@seznam.cz","avatar":null},"body":"Hello,\n\nTo start with, I did not find an official way to submit feature request so hopefully this is the right way to do so - if not then my apologize & appreciate if somebody could re-submit to the proper place.\n\nI'd like to request adding a parameter to 'git branch' that would only show the current branch (w/o the star) - i.e. the outcome should only be the name of the branch that is normally marked with the star when I do 'git branch' command. This may be very helpful in some external scripts that just simply need to know the name of the current branch. I know there are multiple ways to do this today (some described here: http://stackoverflow.com/questions/6245570/how-to-get-current-branch-name-in-git) but I really think that adding simple argument to 'git branch' would be very useful instead of forcing people to use 'workarounds'.\n\nMy suggestion is is to name the parameter '--current' or '--show-current'.\nExample:\n\nCommand: git branch\nOutcome:\n branchA\n branchB\n* master\n\nCommand: git branch --current\nOutcome:\nmaster\n\nThank you,\nMartin\n"},{"id":"256349","messageId":"001801d04c48$732f9980$598ecc80$@nexbridge.com","threadId":"38601","inReplyTo":"13b.3lxh{.41MsIT3sthY.1KvU6v@seznam.cz","subject":"RE: Git Feature Request - show current branch","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2015-02-19T13:32:03Z","receivedAt":"2015-02-19T13:32:03Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"Hi Martin,\n\nI use:\n\ngit symbolic-ref --short HEAD\n\nin scripts. Not sure it's the best way, but it works 100% for me.\n\nRegards,\nRandall\n\n-----Original Message-----\nFrom: git-owner@vger.kernel.org [mailto:git-owner@vger.kernel.org] On Behalf Of mdconf@seznam.cz\nSent: February 19, 2015 8:15 AM\nTo: git@vger.kernel.org\nSubject: Git Feature Request - show current branch\n\nHello,\n\nTo start with, I did not find an official way to submit feature request so hopefully this is the right way to do so - if not then my apologize & appreciate if somebody could re-submit to the proper place.\n\nI'd like to request adding a parameter to 'git branch' that would only show the current branch (w/o the star) - i.e. the outcome should only be the name of the branch that is normally marked with the star when I do 'git branch' command. This may be very helpful in some external scripts that just simply need to know the name of the current branch. I know there are multiple ways to do this today (some described here: http://stackoverflow.com/questions/6245570/how-to-get-current-branch-name-in-git) but I really think that adding simple argument to 'git branch' would be very useful instead of forcing people to use 'workarounds'.\n\nMy suggestion is is to name the parameter '--current' or '--show-current'.\nExample:\n\nCommand: git branch\nOutcome:\n branchA\n branchB\n* master\n\nCommand: git branch --current\nOutcome:\nmaster\n\nThank you,\nMartin\n--\nTo unsubscribe from this list: send the line \"unsubscribe git\" in the body of a message to majordomo@vger.kernel.org More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"256353","messageId":"54E60D71.6050906@drmicha.warpmail.net","threadId":"38601","inReplyTo":"001801d04c48$732f9980$598ecc80$@nexbridge.com","subject":"Re: Git Feature Request - show current branch","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-02-19T16:21:05Z","receivedAt":"2015-02-19T16:21:05Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Randall S. Becker venit, vidit, dixit 19.02.2015 14:32:\n> git symbolic-ref --short HEAD\n\nThat errors out when HEAD is detached.\n\ngit rev-parse --symbolic-full-name [--abbrev-ref] HEAD\n\nreturns the branch name or HEAD. Though it's a bit difficult to discover.\n\nI guess git 3.0 will have \"git branch\" and \"git branches\" :)\n\nMichael\n"},{"id":"256359","messageId":"xmqqr3tlzsao.fsf@gitster.dls.corp.google.com","threadId":"38601","inReplyTo":"54E60D71.6050906@drmicha.warpmail.net","subject":"Re: Git Feature Request - show current branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-19T18:10:07Z","receivedAt":"2015-02-19T18:10:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> Randall S. Becker venit, vidit, dixit 19.02.2015 14:32:\n>> git symbolic-ref --short HEAD\n>\n> That errors out when HEAD is detached.\n\nIsn't that what you would want to happen anyway?\n\n\tif current=$(that command)\n        then\n        \tyou know $current is checked out\n\telse\n        \tyou know HEAD is detached\n\tfi\n\nIf you used another command that gives either the name of the\ncurrent branch or 4-letter H-E-A-D without any other indication, you\ncannot tell if you checked out the \"HEAD\" branch aka refs/heads/HEAD\nor you are not on any branch.  The former would happen after doing\nthis:\n\n    $ git update-ref refs/heads/HEAD HEAD\n    $ git checkout HEAD\n\nOf course, this is not a recommended practice, and \"git branch\"\nthese days refuses to create refs/heads/HEAD to discourage you from\ndoing so by mistake, but there is no guarantee that the repository\nwhatever script you are writing to work in was created and used by\nsane people ;-) so you would want to be defensive, no?\n"},{"id":"256398","messageId":"54E70987.4060904@drmicha.warpmail.net","threadId":"38601","inReplyTo":"xmqqr3tlzsao.fsf@gitster.dls.corp.google.com","subject":"Re: Git Feature Request - show current branch","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-02-20T10:16:39Z","receivedAt":"2015-02-20T10:16:39Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 19.02.2015 19:10:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> Randall S. Becker venit, vidit, dixit 19.02.2015 14:32:\n>>> git symbolic-ref --short HEAD\n>>\n>> That errors out when HEAD is detached.\n> \n> Isn't that what you would want to happen anyway?\n> \n> \tif current=$(that command)\n>         then\n>         \tyou know $current is checked out\n> \telse\n>         \tyou know HEAD is detached\n> \tfi\n> \n> If you used another command that gives either the name of the\n> current branch or 4-letter H-E-A-D without any other indication, you\n> cannot tell if you checked out the \"HEAD\" branch aka refs/heads/HEAD\n> or you are not on any branch.  The former would happen after doing\n> this:\n> \n>     $ git update-ref refs/heads/HEAD HEAD\n>     $ git checkout HEAD\n> \n> Of course, this is not a recommended practice, and \"git branch\"\n> these days refuses to create refs/heads/HEAD to discourage you from\n> doing so by mistake, but there is no guarantee that the repository\n> whatever script you are writing to work in was created and used by\n> sane people ;-) so you would want to be defensive, no?\n> \n\nIf you want to be defenive, don't use --abbrev-ref, just git rev-parse\n--symbolic-full-name  HEAD\n\nThe original request was for a one-liner, I think.\n\nMichael\n"}]}