Skip to content

Instantly share code, notes, and snippets.

@dsvanidze
Forked from calebbrewer/Deploy With Git
Created February 22, 2018 18:01
Show Gist options
  • Select an option

  • Save dsvanidze/e9cd520e46325f5eaf891f99d0531bb2 to your computer and use it in GitHub Desktop.

Select an option

Save dsvanidze/e9cd520e46325f5eaf891f99d0531bb2 to your computer and use it in GitHub Desktop.

Revisions

  1. @calebbrewer calebbrewer revised this gist Jun 26, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Deploy With Git
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Video on this Gist: https://www.youtube.com/watch?v=zvpLDuRY4ss&feature=c4-overview&list=UUj8_147vA3FQ1quI_CjciIQ

    #Initialize a bare repo on the webserver. This would preferably be outside of your public website dir but if you are on a shared host you may not have that option. I like to make a folder just outside of the live folder called git. So for me it would look like this…

    $ cd /var/www
  2. @calebbrewer calebbrewer revised this gist May 31, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Deploy With Git
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    $ cd /var/www
    $ mkdir git && cd git
    $ git init –bare
    $ git init –-bare

    #Now you need to create a post-receive hook that will check out the latest tree from the Git repo you just setup into the /var/www/html folder where you want your website to be. You can make this whatever folder you want your code to end up in.
    #This will create a file called post-receive in the hooks dir of the git repo.
  3. @calebbrewer calebbrewer revised this gist May 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Deploy With Git
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ $ chmod +x hooks/post-receive
    #On your workstation you will now need to add your server as a remote.

    #in your local repo run…
    $ git remote add liveServer [email protected]/var/www/git
    $ git remote add liveServer [email protected]:/var/www/git
    $ git push liveServer +master:refs/heads/master

    #After you type the password for the user the repo on the server will contain a copy of your files and the head pointer of the repo on the server will point to the same commit as your local repo.
  4. @calebbrewer calebbrewer created this gist May 29, 2013.
    31 changes: 31 additions & 0 deletions Deploy With Git
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #Initialize a bare repo on the webserver. This would preferably be outside of your public website dir but if you are on a shared host you may not have that option. I like to make a folder just outside of the live folder called git. So for me it would look like this…

    $ cd /var/www
    $ mkdir git && cd git
    $ git init –bare

    #Now you need to create a post-receive hook that will check out the latest tree from the Git repo you just setup into the /var/www/html folder where you want your website to be. You can make this whatever folder you want your code to end up in.
    #This will create a file called post-receive in the hooks dir of the git repo.

    $ cat > hooks/post-receive
    #Paste this in and remember to change the GIT_WORK_TREE=/var/www/html to whatever dir you want your code in.
    #!/bin/sh
    GIT_WORK_TREE=/var/www/html git checkout -f
    $ chmod +x hooks/post-receive

    #On your workstation you will now need to add your server as a remote.

    #in your local repo run…
    $ git remote add liveServer [email protected]/var/www/git
    $ git push liveServer +master:refs/heads/master

    #After you type the password for the user the repo on the server will contain a copy of your files and the head pointer of the repo on the server will point to the same commit as your local repo.

    #In the future when you are ready to push changes to the web server just type…
    $ git push liveServer

    #The .git/config file on your workstation is where the settings for the remote are kept, so if you need to make any changes to the connection you can do it there.

    #You can also setup an SSL key so that you don’t have to type your password when you push to the repo on the server.

    #keep in mind that all we have done is setup a remote repo on a server, so you could go through this same setup but not checkout the files (code). This would let you use this like your personal Git repo for collaboration (like GitHub).