Deploying my site to the server
I have managed to deploy this website using a really nice blog post by Andrew J. Flemming where he speaks about creating HUB and PRIME git repositories to interact with his server in mediatemple. I followed his steps and just had to change the paths pretty much. Here is a recap.
1. Create the PRIME repository
First I created an empty git repository in the public html
folder of the domain
(This assumes that you have ssh access to your server). Also, I made an
initial commit there.
$ cd /path-to-your-domain/html $ git init $ git add . $ git commit -m "First import"
2. Create the HUB repository
Then I placed the HUB outside the public html
folder, not in
the home
directory as Andrew J. Flemming suggested. I created a folder called repo
which sits inside the domain folder. Inside repo
, I added another folder
called your-domain.git
, which will host a bare git repository (notice
that you can call this folder any way you want, as long as it ends with
.git
, your-domain.git
is just a placeholder in this case).
$ cd /path-to-your-domain/ $ mkdir repo $ cd repo $ mkdir your-domain.git $ cd your-domain.git $ git --bare init
3. Remote and Hooks
Our PRIME repository needs to have a remote
repository in order to get
the files that are part of the website, in this case the
folder we just created your-domain.git
will act as the remote
.
$ cd /path-to-your-domain/html $ git remote add hub /path-to-your-domain/repo/your-domain.git $ git remote show hub $ git push hub master
Then we just need to add two hooks. These will tell the repositories that
we created what to do once they receive new code. Two hooks are needed: a
post-commit
, and a post-update
. The post-commit
, has to be created in
the .git/hooks/
folder of your PRIME repository. We can do this by adding
the following code the post-commit.sample
file and then removing the
.sample
part to activate it.
#!/bin/sh git push hub
If you don't have a post-commit.sample
, just create the post-commit
file directly and add the previous bit of code.
Now we need a post~update
hook that will reside in the
your-domain.git/hooks/
folder. This will tell our HUB to go to the PRIME
repository and then execute a pull from that location for us.
#!/bin/sh cd /path-to-your-domain/html || exit unset GIT_DIR git pull hub master git-update-server-info
4. Push local changes to the HUB
In my case, I had some code in my local repository already since I wanted
to test how the website would look before deploying it to the server. Then
I just had to add a remote
to the local repository as follows:
$ cd /path-to-your-local-repository $ git remote add hub ssh://yourdomain.com@yourdomain.com:/path-to-your-domain/repo/your-domain.git $ git pull hub master
Notice that in the previous code, the line
ssh://yourdomain.com@yourdomain.com:
assumes that you have a username
(part before the @) and the address of the server you want to access (what
comes after the @).
Finally, I was able to push the site I built locally to the server using these commands:
$ git add . $ git commit -m "Initial commit of my website" $ git push hub master
The same procedure can be used for other domains in your server as long as you define a HUB for each of them.