Update your website directly from your git repository

Here is a php script you can use to update your website from your git repository.  You can pass 2 parameters to it:

  • “r” – revision you want checked out from git (r=head works also)
  • “l” – number of log entries you want to view

For example, if I was running it on this site here is what each URL would do:

You need to make sure that the directory structure is owned by the HTTP daemon user (so that the files can be updated.)  It is best to run it initially from the command line as that user on the server to make sure everything is working properly.

One word of caution; you should restrict access to who can run this script (maybe with HTTP-Auth over HTTPS) because the script isn’t perfect and you don’t want to let anyone make changes to your site.  There are also certain security risks that are increased when you have your website files owned by the webserver user.  It is recommended that you only use this script in a protected environment.

/gitpull.php – show current status and last 3 log entries (make no changes)

3 thoughts on “Update your website directly from your git repository”

  1. ############### gitcheckout master ###############
    ############### gitpull ###############

    ############## git branch ##############

    i’ve made a commit and no pull is made

    if i do this directly on server it pulls

    any help

    1. I’d double check the ownership of the directory where you’re trying to checkout and make sure that your webserver user has permissions. Also, look at the webservers error logs for any other hints.

Leave a Reply

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