rjv rjv - 4 months ago 47
PHP Question

Executing git commands via PHP

How can git commands like

git add .
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.

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

Oli Oli

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