Posted by Les | Administration, Programming

In the past I have used Subversion for version control but having to have a repository somewhere put me off from using it on many projects. Git was created in 2005 by Linus Torvald and Linux developers to address their needs for distributed version control.

Git makes it trivial to have a local respository, so when I rework code to be better sturctured or more efficient I can rest assured that the previous working code can be reverted to if it breaks everything.

On Windows 7 I have installed TortoiseGit which integrates nicely with Explorer. Right click on any directory and select “Git Create repository here…” to start and icons will visually show the status of affected files.

You can push your repository to another remote repository for collaborated projects or for deployment.

I use this for deploying projects on to my web host with the following setup.

Create a bare Git repository to receive push to production:
mkdir www.git
cd www.git
git init --bare

Create the production directory, in this example should be “/home/username/www”
cd ..
mkdir www

Add the file “/home/username/www.git/hooks/post-receive” with the following ensuring that GIT_WORK_TREE is the one create above:
#!/bin/sh
GIT_WORK_TREE=/home/username/www
git checkout -f

Make the new script executable:
chmod +x /home/username/www.git/hooks/post-receive

To setup your development side to push to this new deployment repository:
git remote add live ssh://webhostname/home/username/www.git
git push live +master:refs/heads/master

Or in TortoiseGit use the “TortoiseGit >> Push…” and add the remote destination as above.

From then on this information is stored in the development repository and you can just call:
git push live

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

Your email address will not be published. Required fields are marked *