Git and Github

For those of you who have been sleeping under a rock, Git is a revision control system similar to CVS, Subversion, and Bitkeeper. However, unlike CVS and Subversion, Git repositories are completely distributed. And unlike Bitkeeper, it’s open source. It was created with the following five issues in mind:

  • It is a truly distributed (no single point of failure)
  • It is really fast (merges are practically instantaneous)
  • Easy branching (involves the creates of just one 46 byte file)
  • All revisions are always locally available to you
  • What you get out is exactly what you put in (all files are check using the SHA hash)

Linus Torvalds, the created of the Linux Kernel and Git, recently gave a great talk at Google. If you are using SVN or unsure about changing over to Git, I highly recommend listening to his talk. The killer feature of Git, which he emphasizes, is that Git is truly distributed. What this means is that you do not need to be connected to a centralized server in order to make commits, branches, etc…

Why is this important? Because you should always make commits to your repository. A SCM is a tool that should always be available. Not making a commit introduces the possibility of breaking code and not being able to revert to a working working without losing a large chunk of your new code. And reason this is import is what would you do if your SCM’s disk died? Well if your using a non-distributed system, you going to loose your entire projects history. With Git, every repository has the entire project history. With Git, there is not single point of failure! The other feature is trust. With Git, a person can checkout your repository and make commits, branches, whatever… without it effecting your repository. If you like what he has done you can merge, and merges are so easy with Git.

So let’s say that there is some project that you would like to work on. A typical Git work flow is as follows:

git clone git://github.com/mpetnuch/tabula-rasa.git

Now you have a working copy of the repository on your hard disk with the projects complete history! That all you have to do to have your own branch! Now starting hacking away and making changes. After a while you might want to make a commit and then sync your changes with the main branch.

git commit -a
git-pull

This will pull all the code from the main repository and merge it. If there any problems, it will mark the offending code to which you can resolve and then commit again. It’s that easy. Later on you can tell the developer about your changes and he can decide if he want to pull those changes into the main branch. The main thing is that you were able to do all of this without anyone having to intervene or set you up. The Git website has a tutorial for SVN users that covers the basic commands for an SVN users point of which, which I found really helpful when switching over.

Now of course all of the collaborative feature of Git are useless unless you have people to collaborate with! This is where GitHub comes in to play. GitHub not just a web interface to a Git reposiory, is a tool designed to make it easy to participate in that collaboration: fork projects, send pull requests, monitor development, etc… GitHub brings to software development a social aspect. Before it was a hassle to going an open source project to start hacking. First you would have to prove your trust to be able to make commits to the repository.

With GitHub, you just click a button and fork the project. You then have your own copy of the project. You can then hack away at it to your hearts delight. After you think you have made a sizable contribution to the project, push your commits back to GitHub and click on the pull request. The author of the program will be notified of your changes, he can check them out and if he likes them integrate them back into the main trunk.

If you are a Rails developer you really need to check out Git and GitHub. With the release of Rails 2.1, Git has become the SCM of choice. Moreover, most high profile Rails applications (include Rails itself) and plugins are hosted at GitHub. It is the best way to keep up to date on your favorite Rails plugins and contribute. Moreover, it is the best way to really take advantage of all the benefits of Git being a decentralized SCM.

Discuss

Was it good for you, too? Join the discussion »


About the Author

Thumb_diet_coke Michael Petnuch is a graduate math student who enjoys walking on his hands, drinking diet coke, solving math problems, and being silly!