Is there a PHP api for GIT?-ThrowExceptions

Exception or error:

I wonder If there are any APIs or something for php to interact with GIT?

I want to print out information about branches, repositories etcetc, on a web page.

Is this possible?

How to solve:

A quick search turns up a github project https://github.com/kbjr/Git.php – which has a PHP library for accessing git using proc_open and usable in git safe mode.

It seems to be fairly easy to use. According to the api documents, you’d be able to get a list of branches in an array with these commands:

require_once('Git.php');

$repo = Git::open('/path/to/repo');
$branch_array  = $repo->list_branches();

You’d substitute your own repo path. You would need the git commands installed for that to work.

As for creating a whole web page, there are complete systems for this – cgit, gitweb, gitphp and a number of others so it may be worth considering if any of those could be configured to meet your needs before creating a completely new tool.

Leave a Reply

Your email address will not be published. Required fields are marked *