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>";
?>
It is definetly possible. I implemented it in one of my projects.
However you should be careful about permissions.
On linux, usually, the
execcommand will execute using thewww-datauser.So you should allow
www-datato write and read on your work directory.One quick and dirty way to do it is :
chmod o+rw -R git_directory