Re: Notation for current branch?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]