Nostalgicness alert! You can find my current blog here.
Logo Twitter

Geek Tweet

No tweets found.

follow me @nerdess for 100% geekness.

more "Blog Nerdy" articles »

Git by example:
How to update your website on nearlyfreespeech.net via Git

January 2012

So far I’ve used SVN for my version control needs but according to people who know much more about this topic than me Git is better/slimmer/geekier. I thought I’d give it a try but found most of the tutorials a bit too technical so had the idea to create my own, using an actual project as an example - this very website you’re looking at.

I am hosting my website on nearlyfreespeech.net which I really like. That is because I am not tied in with a contract there and only pay-as-I-go for what I use. Plus nearlyfreespeech.net comes with a SSH account as default (!) so I don’t have to go through the hassle and ask for one (because the average hosting provider thinks we all h4xX0r their servers).

This little tutorial will guide you through setting up Git so you can use it to commit stuff from your computer to your websever.

  1. On your computer

    Download and install Git on your computer if you don’t have it already. Then open the Git bash and go to the root of the website you’d like to upload.

    Create a git repository

    git init
    

    Add all your files and folders recursively to the repository

    git add *
    

    Commit the whole lot

    git commit -q -m “Blablabla whatever”
    
  2. Remotely on nearlyfreespeech.net

    You need to install a Git repository remotely on your server now. This repository will essentially be a mirror of the one you have locally on your computer.

    Connect to your webspace on nearlyfreespeech.net via SSH, a good program to do that with is Putty. You find your SSH login information in the “sites” section of your nearlyfreespeech.net account.

    Type the following commands

    mkdir .git
    cd .git
    git init --bare
    

    You have created the remote Git repository, great! Once files are committed to this repository they need to be pushed automatically to your public website folder. Setting this up is quite simple:

    cd hooks
    touch post-receive
    

    This creates a file called “post-receive”. By its name you can guess that this file handles what happens after updates have been received ;-). Open the file with a command line editor of your choice, I like “Pico” so type

    pico post-receive
    

    Add the following line to the file then save and close it:

    GIT_WORK_TREE = /home/public git checkout -f
    

    Adjust the access rights of the file:

    chmod +x post-receive
    
  3. On your computer

    Back at your Git Bash you need to do what I think is “connecting” the local and remote repository:

    git remote add website ssh://nerdess_nerdess(at)ssh.phx.nearlyfreespeech.net/home/public/.git
    

    Don’t fortget to replace nerdess_nerdess with your nearlyfreespeech username.

    All is set up now........it’s time to commit!

    git push website master
    

    When the process has finished check that you didn’t get any error messages.

  4. Remotely on nearlyfreespeech.net

    Go back to your root folder by typing

    cd /home/public
    ls
    

    Now you should see all the files you just committed! Go to the URL of your website, it should be visible now :-)

Please note: You might need to update the database separately if your website needs one because Git doesn’t do that for you.