I have been working for some years with svn and I was happy with it. But I have to admit that git is very cool as well and I started using it a couple months ago. No regrets till now :)
In this post I don’t want to list pros or cons of git versus svn or viceversa but I’d like to share a very simple worflow I’ve adopted to manage my live and dev environments and to keep them in sync through git.
Setup
Live Server
You need to create a bare repository (that we called newrepo.git) somewhere in your live server. I’m assuming that the /var/git/repo
directory has been previously created.
1 2 3 4 |
|
As second step, you should clone the newrepo.git to your webserver root directory, assuming this repo will contain the website files you are working on.
1 2 |
|
Development Server
On your development server, you have to clone the same repository newrepo.git. It is worth to note that the clone has been added the remote url automatically since you are cloning through ssh protocol.
1 2 |
|
Deploy local changes
Development Server
First of all, you should to prevent web access to the .git directory (differently from svn, it exitsts only at your clone root) by creating a .htaccess
file at the same level of .git
folder.
1 2 |
|
1 2 3 |
|
Now add your first extra-complicated index file :)
1
|
|
And sync the changes with your local repository.
1 2 |
|
Last step consists of pushing local changes to the remote repository (with ‘remote repository’ I mean the one on live-server at /var/git/repo/newrepo.git
path).
1
|
|
Live Server
Finally, pull down changes from the newrepo.git repository to the clone in your web server root directory.
1 2 |
|