Website Version Control

From Nottinghack Wiki
Jump to navigation Jump to search

We are bringing the static and custom files on the website into Git to version control them. They are in this repository:

https://github.com/NottingHack/website

None of the Wordpress or Wiki system files are included in the repository, this allows those systems to be updated automatically, without engaging the version control.

Setting up

Set up Git on the Web Server

Many instructions on the web suggest setting up the apache user a SSH key to do passwordless git (such as https://github.com/settings/ssh), but instead we will use the git read only URL:

git://github.com/NottingHack/website.git

Seeing as we never need to commit from the webserver, this should be fine.

So all we need to do is ensure Git is installed, and configured.

Pull the remote repository

Once the repository on Github is set up and populated, we need to set up the server to pull from it, without deleting loads of things off the server. We can't just do a

git clone

as git will complain about untracked files, overwriting, etc. So we need to be a bit sneaky about it.

We are going to be doing this in the main directory (above public_html) as we are also tracking files outside the webroot

First, we create a .gitignore file in the main directory, with just these contents:

*

This tells git to ignore (and overwrite) any files it likes. It also won't ever complain about untracked files during a commit (although we won't be commiting from here anyway). DANGER do not so this on a local filesystem, unless you like losing files. Don't commit the .gitignore file to the repository, or you will mess up everyone's computer!

Now set the main directory as a git repository

git init

Then add the remote

git remote add origin git@github.com:NottingHack/website.git

Pull the data from git (this won't change any files yet).

git pull

Finally, make a new master branch and set it to track the origin master. This will overwrite any files that exist on the webserver with the tracked files, without affecting untracked files. This is what would fail if we hadn't already made the .gitignore file

git checkout --track origin/master

Set up the Update Hook

In the Admin section of the repository, we add the URL of the deploy script to the "WebHook URLs" section. These are the post-receive hooks and each URL will be POSTed to when the repository is updated.