I’m trying to get the branch name for a commit in git.
I’m using the following command:
git name-rev --name-only --always --exclude=tags* HEAD
but if the commit pointed by HEAD contains several branches how can I get the latest that was created from that specific commit
For example, this is the first line of git log
command:
commit 4126555537691488d316d911dd881f0haf64ddbe (HEAD, origin/stage, origin/develop, origin/HEAD, stage, develop)
the git name-rev
command above always, returns develop
, why ?
Can I get all the branches ? can I have a sorted list, somehow ?
I also tried to use git rev-parse --abbrev-ref HEAD
I would like to add the branch name to a version string, so I will know from which branch the code was built.
The issue is that when I branch out from my development branch, i.e. develop, to a different branch, and did not commit anything yet to the 2nd branch I get only develop although I checked out to stage, e.g.
git checkout stage
git name-rev --name-only --always --exclude=tags* HEAD
the result is develop
Thanks.