Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dimd13/f6cf0ec31f67170a1a7b9a2f20c2e8c6 to your computer and use it in GitHub Desktop.
Save dimd13/f6cf0ec31f67170a1a7b9a2f20c2e8c6 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