Home > On the Ground > On the Rails: Set Up Git Repos Locally and On GitHub

On the Rails: Set Up Git Repos Locally and On GitHub

December 31st, 2009

GitHub

Let’s prepare GitHub for our code’s arrival.

  1. Go to github.com.
  2. If you don’t already have an account, click on “Pricing and Signup” at the top and get a free one.
  3. Log in to your account.
  4. Click “New Repository” in the upper right of the “Your Repositories” box.
  5. Give your repo the name “railstest”, along with an appropriate description and URL if you know where your project will live in production (i.e. its hostname).
  6. Click “Create Repository”.

Next, we need to generate an SSH keypair on our local machine, and add the public key to our GitHub account so our local machine can access the GitHub repo we just created. In a Terminal, issue the following command:

ssh-keygen -C "youremail@yourdomain.com" -t rsa

Accept the defaults, and don’t supply a passphrase unless you want to. Now, issue the following command to display the public key:

cat ~/.ssh/id_rsa.pub

Copy the contents of ~/.ssh/id_rsa.pub to the clipboard, and follow these steps:

  1. On GitHub, click “Account Settings” in the upper right of the page.
  2. Click “SSH Public Keys” in the second row of tabs.
  3. Click “Add another public key”.
  4. Give the key a title, like “Jeremy’s Key on MacBook”.
  5. Paste the contents of ~/.ssh/id_rsa.pub from the clipboard into the “Key” textarea.
  6. Click the “Add key” button.

Now, we’re ready to set things up locally.

Locally

With a few additions and modifications, we’ll follow the instructions you saw after creating the repo. In Terminal, from your home directory, issue the following commands in order:

git config --global user.name "Your Name"
git config --global user.email youremail@yourdomain.com
cd workspace/railstest
git init
git add .
git commit -m 'Initial import'
git remote add origin git@github.com:your_github_username/railstest.git
git push origin master

Now, let’s go back to our repo on GitHub and make sure our code made it there OK. That’s it!

Next time: We’ll create a Cloud Server on the Rackspace Cloud, set it up to host our app, and use Capistrano to deploy our code from GitHub to our server. See you then!

Categories: On the Ground Tags:
  1. No comments yet.
Comments are closed.