Home > Installs > Installing Git on Mac OS X Leopard and setting up a public repo on GitHub

Installing Git on Mac OS X Leopard and setting up a public repo on GitHub

January 8th, 2009
logo
Image via Wikipedia

Source control is very important, and very helpful when it comes to writing any type of software, and Git combined with GitHub makes this unbelievably easy.

Installing Git on Mac OS X Leopard couldn’t be easier. Head on over to http://code.google.com/p/git-osx-installer/ and download the git-1.6.1-intel-leopard.dmg disc image. Run the installer on the image and you will have git version 1.6.0.6 installed. Take a look:

git --version

Alright, well now that you have git installed head on over to GitHub and signup for a free account to start. GitHub is super easy to use and has a great Rails community. Check out http://github.com/technoweenie for some great plugins.

Once you have an account, login and click on account. Click on the Global Git Config link and run what it shows in the terminal. It should look something like this:

git config --global github.user neilmcg
git config --global github.token ::token here::

Now it’s time to setup your public ssh key. Repeating how to do this in this blog post would be ridiculous because GitHub has a guide that spells it out perfectly already. Head on over to http://github.com/guides/providing-your-ssh-key#macosx and setup a pubkey for your account.

Now click on your account username and follow the link to a create a new repository. Follow the steps to create a new blank, public repo. I created a repo called ‘githubrepo’ and here are what the steps looked like:

neil-mcgeehans-macbook-pro:Rails neilmcgeehan$ mkdir githubrepo
neil-mcgeehans-macbook-pro:Rails neilmcgeehan$ cd githubrepo
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ git init
Initialized empty Git repository in /Users/neilmcgeehan/Rails/githubrepo/.git/
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ touch README
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ git add README
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ git commit -m 'first commit'Created initial commit 8e6d1f5: first commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ git remote add origin git@github.com:neilmcg/githubrepo.git
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:neilmcg/githubrepo.git
 * [new branch]      master -> master
neil-mcgeehans-macbook-pro:githubrepo neilmcgeehan$ 

Now you have a repo with a blank README in it. Let’s add some code.

Go one directory behind your blank repo, in my case I would “cd ..” out of my githubrepo folder and run:

rails githubrepo

It will ask if you want to overwrite the README, go ahead if you want.

Now cd back into your repo and you should have a blank rails skeleton there. Now to get that in to our repo on GitHub we will do the following while in local repo directory:

git add .
git commit -m "added rails skeleton"
git push

Refresh your repo on GitHub and you will now see the blank rails skeleton reflected.

To explain, “git add .” added anything that has changed since the last push to the repo. Then “git commit -m “added rails skeleton” told git to commit those files with a comment. Finally “git push” actually sends the new/updated files to the public repo on GitHub.

Once you start working on your Rails app you will want to add each file to the repo once you make a change. You can do “git add /path/to/file” but I choose to just use “git add .” each time instead. It will know which file you just changed and it works just the same. Then I commit with a comment and push it to the repo.

That’s it for my intro to Git and GitHub. For more information, check out the guides on GitHub or head over to Git’s website at http://git-scm.com/.

Check back soon for future posts about Rails.

Reblog this post [with Zemanta]

Neil McGeehan Installs , , , , , , , , , ,

  1. No comments yet.
  1. No trackbacks yet.