Monday 20 February 2012

Setting up Git to manage a website project

In the server:

This is where your code lives, in your DocumentRoot:
$ cd /var/www
$ mkdir mysite

This is the remote repository:
$ cd /home/user
$ mkdir mysite.git && mysite.git
$ git init --bare
Initialized empty Git repository in /home/user/mysite.git/
$ vi mysite.git/hooks/post-receive
~
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
~
~
~

And in the local machines:

$ cd /var/www
$ mkdir mysite && cd mysite
$ git init
Initialized empty Git repository in /var/www/mysite/.git/

$ git remote add web ssh://<user>@<server_url>/home/user/mysite.git
$ git push web +master:refs/heads/master

$ echo 'Hello, world!' > index.html
$ git add index.html
$ git commit -m "first commit"
$ git push web

Then:
Another user could clone the remote repository:
git clone ssh://<user>@<server_url>/home/user/mysite.git


No comments:

Post a Comment