I have a Github repository that I use via Atom.io with a client to help keep all the changes for their website synchronized. The GitHub repo contains a webhook that automatically pushes all our changes up to there live website, but I want to use PHP to push changes done directly on the webserver back up to the repo. ie: log file backups, image uploads and quick changes that were made direct on the server.

If one of these changes on the sever happens my scripts tell me about it no problem.

git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#   new file:   somefolder/somenewfile.whatever

If I do this from the command line everything re-syncs perfectly:

git add --all
git commit -m "from server"
git push -u origin master

But if I try doing that via the PHP shell_exec() backticks ` ` nothing happens. I even tried adding pauses.

$output = `git add --all`;
echo $output;

$output = `git commit -m "from server"`;
echo $output;

$output = `git push -u origin master`;
echo $output;

Anyone know what I'm doing wrong here? Should I be placing these calls in a bash script and then calling it via a PHP template?

  • 1
    Your first output line is missing a closing backtick after the command. Is that a typo when copying here or is it actually missing in your script? – Mokubai Oct 4 '18 at 7:21
  • Is the PHP script's current working directory correct? – Attie Oct 4 '18 at 7:50
  • It's also not a great idea to put big / binary files (log files and images) into a git repository on any significant scale... maybe look into Git LFS. – Attie Oct 4 '18 at 7:51
  • @Mokubai that was just a typo here, I've updated my example above. – Vince Oct 4 '18 at 15:40
  • @Attie the PHP script is working correctly in all other ways, even simple git calls like git status work perfectly. The problem is when it trys to call git commit -m "from server", I simply don't see any output to determine if it's even working at all. – Vince Oct 4 '18 at 15:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.