Last active
December 4, 2018 07:16
-
-
Save mgrubinger/0b504b3b364b5b48769b9e17afe40099 to your computer and use it in GitHub Desktop.
Get current Git Branch in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get current Git Branch in PHP | |
See: https://stackoverflow.com/a/7448133/3091226# | |
*/ | |
$stringfromfile = file('.git/HEAD', FILE_USE_INCLUDE_PATH); | |
$firstLine = $stringfromfile[0]; //get the string from the array | |
$explodedstring = explode("/", $firstLine, 3); //seperate out by the "/" in the string | |
$explodedstring = array_slice($explodedstring , 2); | |
$branchname = trim(implode("/", $explodedstring)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment