0

Im trying to get on GIT POST-RECEIVE command the local branch name of computer, i tried the code "READ REF" but it outputs "ref/heads/branchname" i only want the branchname, can someone please help me trim using the output using bash command or is theres a specific code in git to get the local branchname of pushing user.

Thanks

2 Answers2

1

You can try

git symbolic-ref --short HEAD

or

git rev-parse --abbrev-ref HEAD

There's a difference for the two commands for detached HEAD state. The former shows an error message, while the latter one outputs the string HEAD.

For bash command, you can use basename to get the branch name.

branchname=`basename "ref/heads/branchname"`
Landys
  • 7,169
  • 3
  • 25
  • 34
  • 1
    Suggestion: `git symbolic-ref --short HEAD 2>/dev/null`, so that, when you're in detached-HEAD state, nothing is output, not even an error. – jub0bs Sep 21 '14 at 10:53
0

Thanks!

This one is what i need! branchname='basename "ref/heads/branchname"'