rjv rjv - 8 days ago 5
PHP Question

Executing git commands via PHP

How can git commands like

git add .
and
git commit -m
be executed using php?

It is for a project that creates a centralized repository facility for maintaining academic projects.

exec() didn't seem to work.

<?php
$path = "/var/www/repos/$_POST[project]";
$a='';
chdir($path);
exec("git add .");
exec("git commit -m'message'");
echo "<h3 align = center> Succesfully commited all the files.</h3>";
?>

Oli Oli
Answer

It is definetly possible. I implemented it in one of my projects. However you should be careful about permissions.

On linux, usually, the exec command will execute using the www-data user. So you should allow www-data to write and read on your work directory.

One quick and dirty way to do it is : chmod o+rw -R git_directory