GIT deployments are a technique for moving source code from your local development environment to your remote environments while maintaing a complete history of your changes. Many web developers have moved to this style of deployment because it:
- lowers the risk of forgetting to transfer a file when deploying
- gives you a way to back-out changes if your deployment breaks something
- makes it easier to collaborate with other developers, or work from multiple computers i.e. your laptop and the desktop at work
Hub and prime: The web-focused GIT workflow
GIT deployment workflow that works[/caption]
Joe Maller’s web-focused GIT workflow is the workflow I choose to use. Why?
- It is relatively simple
- It can be applied to a live website without any down-time
- It worked
Please go and read the original article because it provides a great explanation on why he uses two repositories set up the way they are.
By following the instructions in the original article and using MediaTemple’s Knowledge base for MediaTemple specific info I got this workflow working. This is a run down for those wanting to do the same.
Connect via SSH
MediaTemple are kind enough to provide GIT pre-installed on their Grid service, but you will need to enable SSH connections before moving on.
When connecting via SSH, the username is your primary domain. So in my case, that’s prevision.com.au.
The following command connected me via SSH:
ssh prevision.com.au@prevision.com.au
The SSH password is the server administrator password, which is the same password you use to connect via FTP. Not your account centre password.
Create Prime repository
Once connected via SSH, the only changes to Joe Maller’s instructions on setting up the Prime repository is the file path to the public html directory.
On MediaTemple’s Grid the public html directory is: ~/domains/yourdomain.com/html
So the commands to set-up your Prime repository become:
$ cd ~/domains/yourdomain.com/html
$ git init
$ git add .
$ git commit -m"initial import of pre-existing web files"
Create Hub repository outside the public html directory
I created a directory called “repos” at the root level of my server and and created the Hub repositories there.
To do this use the following commands instead of those from Joe Maller’s article
$ cd ~; mkdir repos; cd repos
$ mkdir site_hub.git; cd site_hub.git
$ git --bare init
Initialized empty Git repository in ~/repos/site_hub.git
Add remote to Prime
Due to the MediaTemple specific file paths, the command you’ll need to add a remote repository to your Prime repositories becomes:
$ cd ~/domains/yourdomain.com/html
$ git remote add hub ~/repos/site_hub.git
$ git remote show hub
* remote hub
URL: /domains/repos/site_hub.git
$ git push hub master
Create hooks
Hooks are the linch-pin of GIT deployments and it’s no different with this workflow. Again the only thing needing to change from the original article is the file paths, so the commands become:
#!/bin/sh
echo
echo "**** Pulling changes into Prime [Hub's post-update hook]"
echo
cd ~/domains/yourdomain.com/html || exit
unset GIT_DIR
git pull hub master
git-update-server-info
The post-commit hook on in the Prime repository is the same.
Add Hub as a remote on your local repository
The final step is linking your local repository to the Hub repository by adding it as a remote.
The following commands are on your local computer:
$ mkdir yourdomain
$ git init
$ git remote add hub ssh://yourdomain.com@yourdomain.com/~/repos/site_hub.git
$ git pull hub master
If you already have code in a repository locally you can use the following commands to add hub as a remote, and deal with any merge conflicts which arise:
$ cd /path/to/your/repository
$ git remote add hub ssh://yourdomain.com@yourdomain.com/~/repos/site_hub.git
$ git pull hub master
Pushing changes to Hub will deploy them to your live site
Now when you’re ready to deploy changes to your live site, commit them locally then push to Hub. This will trigger the post-update hook on Prime which pulls the changes to your public html directory making the live.
The commands for this are something like:
$ git add .
$ git commit -m "Your descriptive commit message"
$ git push hub master

Leave a Reply to Leo Perkins Cancel reply