While adding the contact link to the bottom of every page the other week, I managed to accidentally upload the new changes and an out-of-date stylesheet, and so messed up the view of the whole website. Live. After testing the changes first. And I learnt two things:
- Fortunately I have my month of daily backups, so restoring wasn’t too painful.
- Version Control (as recommended by @recumbent)
- Even better than backing up, version control would have meant I could rewind the changes immediately.
This isn’t the first time I’ve come across version control, I used git when rewritingTweetUpdater and the WordPress extensions system uses SVN. Git definately made the most sense to me, and I understand the idea of commits and branching and remote repositories (the TweetUpdater code is also hosted on GitHub) and it’s really straight forward to get started with.
From the git-scm quickstart:
cd (project-directory) git init (add some files) git add . git commit -m 'Initial commit'
Creating Remote Repositories
The one thing that did take me a while to figure out was how to take the initial local repository and create a bare remote on another computer.
It’s not possible just specify a remote and then
git push unless that remote has been initialised; and initialising a bare repository on the other computer is out, apparently the git version I’m using doesn’t allow
git init --bare. Also, it’s not possible to use
git clone with a remote target (like
git clone --bare project ssh://remote/path/to/project.git) that just gets you a local repository with the remote path as the folder name!
The best method I could come up with was to: Clone a bare repository locally,
git clone --bare project project.git
then copy the bare repository to the remote location,
scp -r project.git remote:path/to/project.git
then add the remote,
git remote add remote_name remote:path/to/project.git
and clean up the local bare repo,
rm -r project.git
scp Notation for Git Remotes
I was quite pleased when I found out that, as I am using Host definitions in my
$HOME/.ssh/config file, I can use those to simplify the git remote paths:
git remote add remote1 remote1:path/to/repo.git
This is especially handy when the remote computer only accepts ssh connections on a non-standard port number.