On the Rails: Set Up Git Repos Locally and On GitHub
GitHub
Let’s prepare GitHub for our code’s arrival.
- Go to github.com.
- If you don’t already have an account, click on “Pricing and Signup” at the top and get a free one.
- Log in to your account.
- Click “New Repository” in the upper right of the “Your Repositories” box.
- 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).
- 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:
- On GitHub, click “Account Settings” in the upper right of the page.
- Click “SSH Public Keys” in the second row of tabs.
- Click “Add another public key”.
- Give the key a title, like “Jeremy’s Key on MacBook”.
- Paste the contents of ~/.ssh/id_rsa.pub from the clipboard into the “Key” textarea.
- 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!