Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aviaryan/393fbb7d96b133d6dfbd430a21c5e73b to your computer and use it in GitHub Desktop.
Save aviaryan/393fbb7d96b133d6dfbd430a21c5e73b 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment