I\'m kind of new to both EC2 and Git, and I have just set up my first instance of EC2, using a clean Amazon Linux AMI. I also installed MySQL, Apache and PHP and opened some por
I just solved such situation by following the tutorial that Mark Longair pointed before. The only problem I got was in the creation of the bare git repository. So let me resume how I solved it.
/home/ubuntu/.ssh/authorized_keys
file.mkdir sitesrepo.git websites
.cd sitesrepo.git && git init --bare
I created the hook file via vim with the following content in a file named post-receive
and then I made it executable via chmod +x post-receive
(just as the tutorial stated). That file must be placed at /home/ubuntu/sitesrepo.git/hooks
#!/bin/sh
GIT_WORK_TREE=/home/ubuntu/websites git checkout -f
Here's where my steps differ from the tutorial mentioned before: A bare git repository has a conflict where it can't hold the worktree being a bare repository (It doesn't make sense since it's a bare repository. Non-bare repositories are intended to have a working space, i.e. a worktree). Fortunately you can manually set up the repository config
file. So by editing the file /home/ubuntu/sitesrepo.git/config
you must guarantee to have something like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
worktree = /home/ubuntu/websites
[receive]
denycurrentbranch = ignore
Now, at your own machine, at your git local repository working folder, the idea is to add a new remote repository. Currently you have configured by default origin
which tells your repository to push your content into github's repository. The tutorial calls such remote repository web
. So you have to run once: git remote add web ssh://mysite.com/home/ubuntu/sitesrepo.git && git push web +master:refs/heads/master
. The subsequent pushes can be done via a simple git push web
Depending on how many sites you are planning to hold, you must configure your apache sites-enabled hosts. Also, since you're using apache, don't forget to change the web folder to point to /home/ubuntu/websites
, because by default it points to /var/www
But you're ready to go, just don't forget to restart the apache service after defining the new web folder.
Hope this helps with your question.