I have created a bare git repo on my EC2 instance, and I have pushed a branch from my dev machine to it. I can run git log
on the server now and it looks up-to-date with everything.
The dev machine now has two remotes, one "origin" is Bitbucket.org repo where the code lives, and the second "ec2" is the remote I would push to in order to deploy the code. It looks like whenever I push to "ec2" it will basically sync the repo with whatever I grabbed off of Bitbucket. Which is good, though at the back of my mind I'm wondering what I'd have to do differently to construct a different history without the intermediate content. (not important.)
However on the server, the repo is a bare repo and has no working tree.
What is the proper way to get the server to auto-deploy the webapp?
I'd like someone to help me compare and contrast these two methods:
... inside the bare repo on the server ...
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/home/ec2-user/www/webserver-works-off-this-dir
export GIT_WORK_TREE
git checkout -f
Alternatively I think it could make sense to set up a separate git repo, i.e.
... also on the server ...
$ cd /home/ec2-user/www/
$ git clone # ??? How do I clone from localhost bare repo?
... presumably set the post-receive hook in the bare-repo to cd to *this* dir and run git checkout or pull or something...
Oh, also, what does git checkout -f
do? Force overwrite checkout the latest chronological commit? I think there is something implicit that I'm uncertain of. I guess a push
operation must be "attached" to some commit, and this would be the commit in question.