#current branch name
git branch
#or
branch=$(git branch | cut -d ' ' -f 2)
#sha of head
head=$(cat .git/refs/heads/${branch}

I don't know for certain that these will work for all releases.

--
Maranatha!
John McKown
 On Jan 3, 2013 9:41 PM, "Yoshiki Vázquez Baeza" <yoshik...@gmail.com>
wrote:

> Hello everyone,
>
> I'm currently having a problem trying to retrieve the current git branch
> and the current git SHA of a repository, the main problem being that the
> method I'm using does not work in different versions of git. Right now I'm
> pulling out this information with the following two commands:
>
> # first seven chars of the SHA
> git rev-parse --short HEAD
>
> # current branch name
> git rev-parse --abbrev-ref HEAD
>
> The second command does not work in git 1.7 and lower (I think), the first
> command only works in versions greater than or equal to 1.5.2. *What
> would be a more effective way to achieve this without having to check for
> the current git version*?
>
> What I would like would be a command that would work in any git version or
> that has the greatest coverage for the multiple versions available.
>
> Thanks!
>
> Yoshiki.
>
>
>  --
>
>
>

-- 


Reply via email to