📌  相关文章
📜  通过 php 代码示例获取 git 分支

📅  最后修改于: 2022-03-11 14:54:49.633000             🧑  作者: Mango

代码示例1
/**
 * @filename: currentgitbranch.php
 * @usage: Include this file after the '' tag in your project
 * @author Kevin Ridgway 
 */
    $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

    $branchname = $explodedstring[2]; //get the one that is always the branch name

    echo "
Current branch: " . $branchname . "
"; //show it on the page