Git: Getting to do what you want
Git. Git is awesome. I first used it when I
started work on Teknedia. Initially, I was neither
impressed nor distraught by using Git. Sure, I can
push, pull, and do synchronization when it was
needed. That didn't take long for me to learn coming
from Subversion. I git get that. But that
was as far as my understanding went, and it wasn't
until my internship at Dell this past summer that I
decided to really learn how to use it.
Now I think Git is amazing and I often find myself asking myself why I haven't been using it all along. There are a couple of things I really like about Git. However, there is one that stands out the most for me: The ability to branch code very easily. I'm sure Git gets this a lot; it is in fact the first sentence you see on the about page.
The Git feature that really makes it stand apart from nearly every other SCM out there is its branching model.
Git's branching model is pretty awesome and makes itself useful even for solo projects. Say, for example, I'm making a Tetris clone. In Git, all of my code is in a branch called "master". Everything in this branch is stable. But maybe I want to try adding in an experimental feature like adding in differently shaped blocks or rewriting the graphics engine. If I try making changes right away, I put the stability of my code at risk, as both of these require pretty big changes in my code base (although the former not so much depending on how well you wrote your code for reusability).
In any case, I can just tell Git to create a new branch, for example:
git checkout -b experiment
This moves me from "master" to a new branch called "experiment", which happens instantaneously as far as I can tell. In addition, everything that was on my "master" branch is copied over to my "experiment" branch. Now, I can go ahead and make changes. This may seem pointless at first, but then let's say that in the middle of rewriting the graphics engine I completely mess up and the game no longer resembles the game of Tetris, instead liking itself to surreal abstract art. Now imagine one of my friends walks in and asks to see this Tetris clone that I've boasting about on Facebook all the time.
git checkout master
This moves me back from my "experiment" branch back to my "master" branch. As you may remember, my "master" branch contained all of the code that was stable and running nicely, so now I have something I can show to my friend.
Later, after my friend leaves, I can go back to my "experiment" branch, hopefully fix the myriad of bugs I've introduced, make the graphics look super shiny, and merge the code from experiment back into the master branch for a super shiny edition of another Tetris clone. In the case that I think that the code is helpless and a mess, I can just discard the branch and continue where I left off in the master branch as if nothing ever happened. I can even conduct multiple experiments at the same time, like doing both the graphic engine changes and adding different shapes to Tetris in different branches, without worrying about compromising my code to the point of no return where the game no longer works.
What's even cooler is that I don't have to use this for code. I could just as easily use Git for a writing project, which I believe would actually be really useful, although I haven't tried it yet.
Git lets me do what I want, when I want, without worrying about how it will effect what I've made already.
That's why I think Git is awesome.