Skip to content

Instantly share code, notes, and snippets.

@richardkall
Last active September 11, 2017 20:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save richardkall/3966859 to your computer and use it in GitHub Desktop.
Save richardkall/3966859 to your computer and use it in GitHub Desktop.

Setup remote git repo on EC2

Create a bare repository

$ mkdir <repo-name>.git
$ cd <repo-name>.git
$ git init --bare

Set GIT_WORK_TREE

$ mkdir /var/www/html
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/html git checkout -f

$ chmod +x hooks/post-receive

Setup SSH

$ ssh-add <path-to-ec2-ssh-key>.pem

Add git remote

$ git remote add ec2 ssh://ec2-user@<amazon-server-address>/<repo-path.git>
$ git push ec2 +master:refs/heads/master
@BKemi
Copy link

BKemi commented Apr 10, 2017

This was quite helpful however, I had trouble setting up the GIT_WORK_TREE.

  1. I was unable to mkdir /var/www/html -- it said file already exists.
  2. I was unable to cat > hooks/post-receive it said Permission denied even with sudo.

Any help? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment