Skip to content

Instantly share code, notes, and snippets.

@dertin
Last active January 17, 2024 12:40
Show Gist options
  • Save dertin/cb9bf0ff276b54803f898c5240b27d3b to your computer and use it in GitHub Desktop.
Save dertin/cb9bf0ff276b54803f898c5240b27d3b to your computer and use it in GitHub Desktop.

Revisions

  1. dertin revised this gist Apr 4, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ $ git push ec2 +master:refs/heads/master

    note: only have to use “+master:refs/heads/master for 1st push

    ## To push to remote repo in future:
    ### to push to remote repo in future:

    $ git push ec2 master

  2. dertin revised this gist Apr 4, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,9 @@ $ cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "ca
    ### on remote server: create bare git directory

    $ cd ~

    $ mkdir ProjectDir.git && cd ProjectDir.git

    $ git init --bare

    ### on remote server: create post-receive hook
    @@ -48,7 +50,9 @@ $ chmod +x hooks/post-receive
    ### on local machine: init repo and add remote repository

    $ git init

    $ git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git

    $ git push ec2 +master:refs/heads/master

    note: only have to use “+master:refs/heads/master for 1st push
  3. dertin revised this gist Apr 4, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,8 @@ $ git push ec2 master

    #### add to .git/config in local repo

    ```[remote "all"]
    ```
    [remote "all"]
    url = https://github.com/YourGitAccount/ProjectDir.git
    url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git
    ```
  4. dertin revised this gist Apr 4, 2019. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -47,9 +47,9 @@ $ chmod +x hooks/post-receive

    ### on local machine: init repo and add remote repository

    $ git init
    $ git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
    $ git push ec2 +master:refs/heads/master
    $ git init
    $ git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
    $ git push ec2 +master:refs/heads/master

    note: only have to use “+master:refs/heads/master for 1st push

    @@ -61,9 +61,10 @@ $ git push ec2 master

    #### add to .git/config in local repo

    [remote "all"]
    ```[remote "all"]
    url = https://github.com/YourGitAccount/ProjectDir.git
    url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git
    ```
    #### push to both repos simultaneously

  5. dertin revised this gist Apr 4, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,8 @@ if [ "master" == "$branch" ]; then
    echo "End Post Receive"
    fi
    echo '--- --- --- --- --- --- --- --- --- --- ---'```
    echo '--- --- --- --- --- --- --- --- --- --- ---'
    ```

    $ chmod +x hooks/post-receive

  6. dertin revised this gist Apr 4, 2019. 1 changed file with 27 additions and 5 deletions.
    32 changes: 27 additions & 5 deletions git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -14,11 +14,33 @@ $ git init --bare

    ### on remote server: create post-receive hook

    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/home/ubuntu/www/yourdomain.com
    export GIT_WORK_TREE
    git checkout -f
    $ nano hooks/post-receive
    ```#!/bin/bash
    echo '--- --- --- --- --- --- --- --- --- --- ---'
    echo 'Deploying site...'
    echo '--- --- --- --- --- --- --- --- --- --- ---'
    if ! [ -t 0 ]; then
    read -a ref
    fi
    IFS='/' read -ra REF <<< "${ref[2]}"
    branch="${REF[2]}"
    # Master Branch
    if [ "master" == "$branch" ]; then
    echo "Master Post Receive"
    readonly HTTP_HOST=example.com
    readonly REMOTE_TARGET=/var/www/webdisk/${HTTP_HOST}/htdocs/
    GIT_WORK_TREE=${REMOTE_TARGET}
    export GIT_WORK_TREE
    git checkout -f
    echo "End Post Receive"
    fi
    echo '--- --- --- --- --- --- --- --- --- --- ---'```
    $ chmod +x hooks/post-receive
  7. dertin revised this gist Apr 4, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ##Git deploy setup:
    ## Git deploy setup:

    ### http://www.jeffhoefs.com/2012/09/setup-git-deploy-for-aws-ec2-ubuntu-instance/

  8. dertin revised this gist Apr 4, 2019. 1 changed file with 22 additions and 13 deletions.
    35 changes: 22 additions & 13 deletions git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -1,38 +1,47 @@
    ##Git deploy setup:

    ### http://www.jeffhoefs.com/2012/09/setup-git-deploy-for-aws-ec2-ubuntu-instance/

    Git deploy setup:
    1. copy your public key to your ec2 instance:
    ### copy your public key to your ec2 instance:

    $ cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "cat>> .ssh/authorized_keys"

    cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "cat>> .ssh/authorized_keys"
    2. on remote server: create bare git directory
    ### on remote server: create bare git directory

    $ cd ~
    $ mkdir ProjectDir.git && cd ProjectDir.git
    $ git init --bare
    3. on remote server: create post-receive hook

    ### on remote server: create post-receive hook

    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/home/ubuntu/www/yourdomain.com
    export GIT_WORK_TREE
    git checkout -f

    $ chmod +x hooks/post-receive
    4. on local machine: init repo and add remote repository

    git init
    git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
    git push ec2 +master:refs/heads/master
    ### on local machine: init repo and add remote repository

    $ git init
    $ git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
    $ git push ec2 +master:refs/heads/master

    note: only have to use “+master:refs/heads/master for 1st push

    To push to remote repo in future:
    ## To push to remote repo in future:

    $ git push ec2 master
    Push to multiple remote repos with one command
    1. add to .git/config in local repo

    ### Push to multiple remote repos with one command

    #### add to .git/config in local repo

    [remote "all"]
    url = https://github.com/YourGitAccount/ProjectDir.git
    url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git
    2. push to both repos simultaneously

    #### push to both repos simultaneously

    $ git push all master
  9. dertin revised this gist Apr 4, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # http://www.jeffhoefs.com/2012/09/setup-git-deploy-for-aws-ec2-ubuntu-instance/
    ### http://www.jeffhoefs.com/2012/09/setup-git-deploy-for-aws-ec2-ubuntu-instance/

    Git deploy setup:
    1. copy your public key to your ec2 instance:
  10. dertin created this gist Apr 4, 2019.
    38 changes: 38 additions & 0 deletions git-deploy-aws.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    # http://www.jeffhoefs.com/2012/09/setup-git-deploy-for-aws-ec2-ubuntu-instance/

    Git deploy setup:
    1. copy your public key to your ec2 instance:

    cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "cat>> .ssh/authorized_keys"
    2. on remote server: create bare git directory

    $ cd ~
    $ mkdir ProjectDir.git && cd ProjectDir.git
    $ git init --bare
    3. on remote server: create post-receive hook

    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/home/ubuntu/www/yourdomain.com
    export GIT_WORK_TREE
    git checkout -f
    $ chmod +x hooks/post-receive
    4. on local machine: init repo and add remote repository

    git init
    git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
    git push ec2 +master:refs/heads/master
    note: only have to use “+master:refs/heads/master for 1st push

    To push to remote repo in future:

    $ git push ec2 master
    Push to multiple remote repos with one command
    1. add to .git/config in local repo

    [remote "all"]
    url = https://github.com/YourGitAccount/ProjectDir.git
    url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git
    2. push to both repos simultaneously

    $ git push all master