Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse current branch name from Git repository and conditionally set WordPress database name.
<?php
$git_head = file('.git/HEAD', FILE_USE_INCLUDE_PATH);
$git_head = $git_head[0]; //get the string from the array
$git_head = explode("/", $git_head); //separate out by the "/" in the string
$branch_name = trim($git_head[2]); //get the one that is always the branch name
if($branch_name == "master")
{
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress_local');
}
else
{
define('DB_NAME', 'wordpress_new');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment