Git is a much better choice but not all shared hosts have git yet. For now we will use SVN.
Since we want the actual web site to be the repository for files we need to create the repository there. With our hosting server housing the repository it allows multiple people to work on the files. First shell into your box and create the repository. You can name the repository whatever you want, I decided to name it ‘repo’.
$[remote] svnadmin create repo
Get your working directory with…
$[remote] pwd
/home/nick/nickhammond.com
Next, lets upload the files for your site. Use your favorite archive format or just upload the folders over ftp, whichever you prefer. After your files have been uploaded we need to notify the repository of the files we want in there and it will also copy them in there at the same time. My files now exist at…
/home/nick/nickhammond.com/site
Importing files…
$[remote] svn import site file:///home/nick/nickhammond.com/repo/site -m “Initial import of my site into svn”
Using the -m trigger lets you make a comment about your action, svn requires you to make a comment with a text editor or inline like demonstrated above.
Most people also recommend that you import your project into the trunk directory. This allows for better coordination later with branching and such.
Now all of our files are in the svn repository ‘repo’, but not really easily visible, it’s in svn land. I don’t want to go into that for this tutorial but basically you can list your repos in there with the list or look command.
Our ’site’ directory still exists but it isn’t a working svn folder, SVN wouldn’t know how to update the folder since it isn’t a ‘checkout’ from the repository. The import command doesn’t touch this folder, it leaves it as is. We want this to be a working copy of our repository though so we might as well delete it and pull out a copy from our repository.
$[remote] svn checkout file:///home/nick/nickhammond.com/repo/site
Now view the contents of your current directory. Sweet, it created the directory you just deleted. If you look inside it though it has a hidden .svn directory which means it is now a working copy from your repository. But you say you want to work locally on it and just push updates to the server?
$[local] svn checkout svn+ssh://some_shell_user@nickhammond.com/home/nick/nickhammond.com/repo/site
There you go, now you have a working local copy. Now everytime you go to work on your working local copy just make sure that you run ’svn update’ to get the latest version pulled down to your local copy. This ensures that you pull in new versions that could have been created by someone else.
After you are finished editing files locally and want to publish your changes to the remote repo just run ’svn commit -m “I updated the readme file and added in a couple css styles”‘
Then ssh back into your site and cd into your ’site’ directory and run ’svn update’ since the previous commit command just updated the repository, not the working copy on the server, this copies over all of the changes.
Sweet, now everything is in sync and we don’t have to worry about which files we modified to fix that bug we were working on, svn does it for us.
It is also worth noting that you should never have your repo public facing or accessible by anyone on the web. not safe.