The Secret to Using Git

February 8, 2014

When git came around, it was not like any other version control system most developers had seen. It certainly wasn't like any version control system I had seen. As open source projects started using it (namely the Linux kernel), I was forced into at least using it for basic things. Those basic things eventually turned into operations and sets of commands without really getting what was going on. That turned into hours of frustration and attempting to use git-svn to continue using svn. Then, I studied rebase and it all started to make sense. Fast forward 4 years and now I can tell you the secret to understanding git in one sentence.

Git is a tool for managing a graph of commits.

That's it. Is that everything you need to know? Of course not. However, in every operation that you do and every conceptual picture you make, this is the common denominator. It's the relationship you will have with git and it will have with you. It really is that simple.

Let me explain. Snapshots, normally called commits, are arranged into a graph called a Directed Acyclic Graph (DAG). This is your repository. Whenever you see an explanation of how a command is modifying the graph of commits in your repository, you're going to see a DAG similar to this:

gitBranch2.gif

Don't get caught up on DAG, it just describes the graph: the history is in one direction and it can't have circles. A commit is a picture of all your files at a specific point. A commit, and its entire history, is uniquely identified by a hash or optional human-readable pointers called branches and tags. Or, you can even identify commits relative to other commits (think: commit X + 5).

Git is simply a tool for observing, creating, changing, copying, moving, merging, and deleting commits in the graph - and it does the job very, very well. Now, there are a number of ways to manage commits with tons of options which in some cases are efficient and not so efficient in others (in terms of the work you have to do to get what you want).

If you have to plan out your commits, or manually do common operations, or think heavily about how you should do something before you do it then you're probably not doing it right. If you want to do something, but just don't know how, you're on the right track.

If you want to know more, read the Pro Git book. It will save you a lot of time in the long run.

Related Posts

2 Comments

Comment February 25, 2014 by anonymous
I didn't never understand until this comment has been made. "All that will continue to come right back to all you need to know to understand git." This simple thing came back to all my understanding of what is needed for easy use.
Comment February 25, 2014 by digitalpeer
Yea, even I had to read that a couple times. Deleted the sentence all together.