Skip to content
steveklabnik edited this page Sep 13, 2010 · 1 revision

git is a really awesome tool. It’s used extensively to manage the source code of Hackety Hack, so it’s well worth learning. This is just enough git to get you going.

Getting Git

The first thing that you need… is to install git! Check out the home page to download it for your platform: http://git-scm.com/

Using Git to Get Hackety

Okay, so you’ve got git. Great! Time to make your own copy of the source code and pull it down to your computer! Make sure you’ve forked the repository on GitHub, which should give you your own repository at http://github.com/YOURUSERNAME/hacketyhack .

From there, type this to clone your fork and get the source:

$ git clone http://github.com/YOURUSERNAME/hacketyhack.git

This will give you a hacketyhack directory, which will contain all of the source code!

Now, hack away! When you’re done with your changes, you need to ‘commit’ them. This tells git that you’re ready to share your changes with others. To do this, just type this:

$ git add .
$ git commit -m "This is what I did."

The ‘git add .’ says “I’d like to add every file to this commit,” and the ‘-m’ flag says “This is the message I’d like to use for this commit.” Commit messages are really important, so try to write good ones! A good message will explain in a few words what changes you made. This way, it’s easy to search through the history of the project to find out things later. Plus, if you’ve edited a lot of code, other hackers aren’t going to want to read hundreds of lines just to see what’s going on! They should just be able to read the commit message instead.

Now that you’ve made a new commit, it’s time to tell the world! Run this:

$ git push origin master

… and now if you check out your GitHub, the new commit should show up!

Last, make a post to the mailing list, or send me a pull request by clicking the button on GitHub! I’ll check out your changes, and merge them into the main Hackety source!

Updating your Hackety

Once other people have made changes, you’ll want to pull them into your copy of the code. When new changes happen, use git fetch and git merge to get them!

First, you’ll have to do this one time set up step:

$ git remote add hackety http://github.com/hacketyhack/hacketyhack.git

This will add a remote branch named ‘hackety.’

After that’s set up, every time you want to get changes, run these two commands:

$ git fetch hackety
$ git merge hackety/master

git fetch downloads the changes, and git merge merges them into your code.

You may see a message about ‘merge conflicts.’ This happens when code you were working on changes things that were also changed in the main source. Open the files that git told you about, and look for the lines that look something like this:

<<<<<< HEAD
  x + 1
==============
  x + 2
>>>>>> LATEST 23f32ec

This shows the part that’s conflicted. In this case, git isn’t sure if you want x + 1 or x + 2. The ‘====’ line splits between the two versions, and they end between the <<< and >>>s. Just delete the one that doesn’t make sense, along with the >>>, <<<, and === lines. Then git commit, and you’ll be good!

More Resources

Here are some other things that you can read if you’d like to learn more about git:

  1. Git Ready
  2. Git for Computer Scientists
  3. Git by example
  4. Git Magic
  5. ProGit
  6. A Gaggle of Git Tips

Clone this wiki locally