Setup: Building a CMS, Part 1

Lets create a website.

Init

First of all, of course you are going to keep your codebase in a versioned repository. Even if you never share it, it is best to version your code. If you get to choose what version control system (VCS) you are going to use, the best choice today is git. SVN, Mercurial, and SourceSafe are other options. For this project I will be using git.

If you know that you are going to host your repository (repo) on a site such as github, then the easiest thing is to create the repo on the site, fork it, and download it. Easy is boring. Lets create an empty repo on github, create a ruby app locally, initialize a repo in for the app, then tell it about the github repo.

Rails New

Go to the directory that will be the parent directory of your rails app directory.

[shell]
$ cd /path/to/my/website
$ rails new site
[/shell]

This will create a new directory called ‘site’. Inside that directory will be the app and also the git repo.

[shell]
$ cd site
$ git init
$ git add .
$ git commit -m ‘My first commit, I am getting so much done!’
[/shell]

(If you use an exclamation mark, use single quotes.)

The vanilla rails app is now committed to the master branch of the git repo. Now lets connect it to a remote repository. I will be using github.

We need to create the remote repo, get the URL, and add it to our local repo.

Sign in to Github. At the top right, find the plus sign and click it to add a new repository. Give it a catchy title, a snarky description and decide if it is going to be public or private. Do NOT seed it with a file. Click create.

On the next screen, under “Quick Setup”, copy the SSH URL for the repo.

git@github.com:[your username]/[your catchy repo name].git

Now back to the console. We are going to add that SSH URL as a remote, viz. “origin”.

[shell]
$ git remote add origin git@github.com:[your username]/[your catchy repo name].git
[/shell]

I committed to the master branch. Let’s push it up.

[shell]
$ git push origin master
[/shell]

Violin! We now have a repo on Github.