Git Local Repository Automated Deployment on Live Of Changes to the Remote Web Server

October 31, 2011 | By Duchateaux.

You dispose of a Git Repository on your Web Server and you want an Automatic Deployment on Live of Changes after a Local Push to Origin.

  1. The Local Repository must Exactly Know his Origin and this is potential in two Ways:

    1. If your Local is a Clone of the Remote one
      The Cloning Procedure is like:

      git clone ssh://USERNAME@:2222/path/To/Your/remoteRepo.git localRepo

    2. Your Origin has been set on the .git/config local file
      One way to Set the Origin by a Command is:

      git remote add origin ssh://USERNAME@:2222/path/To/Your/remoteRepo.git

  2. Next you need Make a hooks/post-receive file inside of the Remote Repo.
    You can follow this Procedure:

    ssh -p  USERNAME@
    cd path/To/Your/remoteRepo.git
    touch hooks/post-receive
    chmod +x hooks/post-receive
    pico hooks/post-receive

    Insert in the post-receive file a Content like this below:

    #!/bin/bash
    #CONFIG
    LIVE="/path/To/Your/liveRepo"
    read oldrev newrev refname
    /nif [ $refname = "refs/heads/master" ]; then
    /necho "************* DEPLOYING TO LIVE SITE ******************"
    /nunset GIT_DIR
    cd $LIVE
    git pull origin master
    /necho "********************* DONE ****************************"
    fi

    (It’s Essential to Leave a White Space between brackets “[]” and “$refname”)
    Save and exit with:

    Ctrl+x

    Now your Remote Repository is Set to Automated Deployment of Changes on Live for every Local:

    git push origin master

    Every Change you Push on your Remote Repo will be Now Automatically Reflected on Live.

  3. Check this..


    Bloogger Blogger, Google Blogger, Google Google

    Apache Virtual Host


QuickChic Theme • Powered by WordPress