# Any way to get Git branch name into a variable?

**URL:** https://www.finalbuilder.com/forums/t/any-way-to-get-git-branch-name-into-a-variable/2554
**Category:** Discussion
**Created:** [July 9, 2017, 2:09am UTC](https://www.finalbuilder.com/forums/t/any-way-to-get-git-branch-name-into-a-variable/2554 "2017-07-09T02:09:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mikef74](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mikef74](https://www.finalbuilder.com/forums/u/mikef74)
#### Post date: [July 9, 2017, 2:09am UTC](https://www.finalbuilder.com/forums/t/any-way-to-get-git-branch-name-into-a-variable/2554/1 "2017-07-09T02:09:13Z")

</div>

I need to know what branch I’m to do certain things based on the branch being run.&nbsp; I can’t see any way to do this with the current set of Git-based actions.  
  
If there is a way, please let me know.&nbsp; If there isn’t currently a way, could you please create such an action.  
  
Based on some googling, here are the commands to get just the current branch name out of Git.&nbsp; These don’t work on detached HEADs.  
  
git symbolic-ref HEAD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Shows full refspec, v1.8+)  
git symbolic-ref --short HEAD&nbsp;&nbsp; (just the branch name, v1.8+)  
git rev-parse --abrev-ref HEAD (just branch name, v1.7+)  
  
of course, in all versions you can just do “git branch” and find the entry with the asterisk.  
  
I was trying to look for an action that allows you to run something form the command prompt and act on its output, but I couldn’t not find one.

---

<div class="post-metadata">

### Author: ![mikef74](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/dc4da7/32.png) [@mikef74](https://www.finalbuilder.com/forums/u/mikef74)
#### Post date: [July 9, 2017, 3:38am UTC](https://www.finalbuilder.com/forums/t/any-way-to-get-git-branch-name-into-a-variable/2554/2 "2017-07-09T03:38:34Z")

</div>

I figured it out on my own, but it would be nice if this was baked into its own action.   
  
 My solution was to log the output of a “Git Generic” into a variable, using one of the commands from my previous post. Then used SubString and Trimming actions.
