Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eritislami/3491e1e7465f3a2f5070a44f53f4fca8 to your computer and use it in GitHub Desktop.
Save eritislami/3491e1e7465f3a2f5070a44f53f4fca8 to your computer and use it in GitHub Desktop.
Get current git HEAD using PHP
<?php
/**
* Get the hash of the current git HEAD
* @param str $branch The git branch to check
* @return mixed Either the hash or a boolean false
*/
function get_current_git_commit( $branch='master' ) {
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
return $hash;
} else {
return false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment