Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

189 lines (130 sloc) 11.752 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Learn.GitHub - Introduction To Git</title>
<script type="text/javascript" src="../js/jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="../js/thickbox-compressed.js"></script>
<script type="text/javascript" src="../js/jquery.corner.js"></script>
<link rel="stylesheet" href="../css/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="../css/print.css" type="text/css" media="print">
<!--[if IE]>
<link rel="stylesheet" href="../css/ie.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8"/>
<link rel="stylesheet" href="../css/thickbox.css" type="text/css" media="screen"/>
<div class="container">
<div class="span-21" id="header">
<div class="span-10">
<a href="/"><img src="../images/learn.github.png" alt="github learn logo" /></a>
<div class="span-11 last">
<div id="links">
<a href="">home</a>
<a href="">login</a>
<a href="">signup!</a>
<div class="span-21" id="welcome">
<h1>Introduction To Git</h1>
<p>What Git is, why you would want to use it and where to get it and learn about it.</p>
<div class="content">
<div class="span-21"><center><embed src="" type="application/x-shockwave-flash" width="790" height="430" allowscriptaccess="always" allowfullscreen="true"></embed></center><hr/><p>Welcome to the first lesson of the GitHub Learning course. This course will lead you through a series of lessons that will demonstrate how to use Git quickly and easily - many of the lessons will have screencasts that you can watch as well, if you learn better that way.</p>
<p>This chapter is about what Git is and why you should use it - just a quick introduction before we start using it.</p>
<p>Git is a <strong>fast, open source, distributed version</strong> control system that is quickly replacing subversion in open source and corporate programming communities.</p>
<h3 id='version_control_system'>version control system</h3>
<p>First off, Git is a <em>version control system</em>, a simple command line tool for keeping a history on the state of your source code projects. You use it as you might use something like Subversion, CVS or Perforce.</p>
<p>You tell it to track files in your project and periodically commit the state of the project when you want a saved point. Then you can share that history with other developers for collaboration, merge between their work and yours, and compare or revert to previous versions of the project or individual files.</p>
<p>As it is primarily a command line tool, most of the examples in this course will show the command line versions of the functions. We will be using a recent version of Git (the 1.7 series) for the examples in this course. We recommend upgrading to the 1.7 series if your version of Git is older - there have been a number of UI improvements that make Git a bit easier to use.</p>
<pre><code>$ git --version
git version 1.7.1</code></pre>
<p>If you need help with any of the commands, you can type &#8217;&#8211;help&#8217; and it will show you the <em>man</em> page. You can also type &#8216;git help <em>command</em>&#8217; for the same thing.</p>
<pre><code>$ git log --help
$ git help log</code></pre>
<h3 id='open_source'>open source</h3>
<p>Git is an open source project, that has been active for several years and is written mostly in C.</p>
<p><img alt='Git Language Breakdown' src='../images/git-lang.png' /></p>
<p>At any time you can get the full source code to analyze or improve upon. To get a download of the source code, visit <a href=''></a>. Git is licensed under the GNU General Public License.</p>
<h3 id='offline_and_fast'>offline and fast</h3>
<p>Git is fully distributed, which means that it can work almost entirely offline. In stark contrast to VCS tools like Perforce or Subversion, Git does nearly all of its operations without needing a network connection, including history viewing, difference viewing and commiting.</p>
<p>This also means that Git is very fast compared to those systems partially due to the fact that none of these operations has any dependency on network latency. For example, take a look at how fast the simple &#8216;log&#8217; command takes to run in Git and in Subversion.</p>
<pre><code>[master]$ time git log &gt; /dev/null
real 0m0.352s
user 0m0.300s
sys 0m0.034s
$ time svn log &gt; /dev/null
real 0m3.709s
user 0m0.482s
sys 0m0.168s</code></pre>
<p>Git at 0.3 seconds vs Subversion at 3.7 seconds. That is a difference of a full order of magnatude. You&#8217;ll find similar differences with nearly any command comparison. For example, adding the popular famfamfam icon set and committing them. Since you can separate the commit from the network &#8216;push&#8217; in Git, this action takes a quarter of a second in Git, but 45 seconds in Subversion.</p>
<pre><code>time &#39;git add icons; git commit -m &quot;added icons&quot;&#39;
real 0m0.273s
user 0m0.032s
sys 0m0.008s
time &#39;svn add icons; svn commit -m &quot;added icons&quot;&#39;
real 0m45.276s
user 0m15.997s
sys 0m5.503s</code></pre>
<p>Even if you needed to push to a shared repository at that time as well, it still takes far, far less time than Subversion.</p>
<pre><code>time git push
real 0m6.219s
user 0m0.023s
sys 0m0.011s</code></pre>
<p>If you just want to commit and keep working, you&#8217;re looking at a huge time difference - one that severely changes your workflow. Most commands in Git seem instantaneous - no more typing &#8216;svn commit&#8217; and then going for a cup of coffee.</p>
<h3 id='small_vs_svn'>small (vs svn)</h3>
<p>Git is also very space efficient. For example, if you import the Django project from SVN into Git and compare their checkout/clone sizes, Git comes out very favorably.</p>
<pre><code>$ du -d 1 -h
44M ./django-git
53M ./django-svn</code></pre>
<p>Interestingly, it is even smaller than the Subversion checkout, which is pretty amazing, considering that the Git clone contains the entire history of the project - every version of every file back to the first commit, whereas the Subversion checkout is just the last version of the project.</p>
<h3 id='snapshots_not_changesets'>snapshots, not changesets</h3>
<p>Unlike most other VCSs, Git is snapshot based. That is, instead of thinking about and storing commit points as file based patches or changes, it stores it as a simple snapshot of what your project looked like when you committed.</p>
<p>Commits, then, are simply objects that contain some metadata about the commit (the message, author, date, etc), a pointer to a single snapshot of the project and pointers to the commit(s) that came directly before it. Git&#8217;s commit history and data model is really just a directed graph - a simple series of snapshots.</p>
<p><img alt='Git Data Model' src='../images/snapshots.png' /></p>
<p>Keeping this in mind is helpful when you&#8217;re thinking about what Git will do in a given situation.</p>
<p>For a more in-depth examination of how Git stores data, checkout <a href=''>Git for Computer Scientists</a>.</p>
<h3 id='cheap_branching_and_easy_merging'>cheap branching and easy merging</h3>
<p>Probably the most compelling feature of Git, since it often fundamentally changes the way that many developers work, is Gits branching model. Instead of the popular VCS branching method of simply cloning into a separate directory for a branch, Git lets you switch between branches in a single working directory. Add to that the fact that creating and switching between branches is nearly instant, not all of your branches need to be shared, and it&#8217;s easy to stash partially completed work - means that the way you work can be incredibly different.</p>
<p>Instead of only having branches for major development line departures, Git developers routinely create, merge and destroy multiple branches a week, or even per day. Often each feature or bug you are working on can have its own branch, merged in only when it is complete. This model allows you to experiment quickly, easily and safely - without having to go through hoops to get back to where you where. It enables and encourages a <em>non-linear</em> development cycle, where you can work on multiple lines of thought in parallel without them stepping on each other.</p>
<p>Many developers feel that this is so incredibly helpful and has changed their workflow and productivity so much that they dub it the <a href=''>&#8220;killer feature&#8221;</a> of Git.</p>
<h3 id='installing_git'>installing git</h3>
<p>See the <a href=''>Pro Git Book</a> for details on how to install Git on your particular operating system. Or, simply go to the <a href=''>download</a> page on to get the source or an installer for your system.</p>
<h3 id='resources'>resources</h3>
<p>For more information on Git, the homepage is at <a href=''></a>. We will also be referring heavily to the CC-licenced <a href=''>Pro Git Book</a> for more information on each of these sections.</p><br/><br/><hr/></div><div class="span-10">&nbsp;</div><div style="text-align:right" class="span-11 last"><a href="setup.html">Setup and Initialization &raquo;</a></div><div class="span-24 last">&nbsp;</div><hr/>
<div id="footer" class="span-21">
<div class="info span-12">
<div class="links">
<a href="">T-Shirts</a> |
<a href="">Blog</a> |
<a href="">Contact &amp; Support </a> |
<a href="">Git Training</a> |
<a href="">Google Groups</a> |
<a href="">Status</a>
<div class="company">
&copy; 2012 GitHub Inc. All rights reserved. | <a href="">Terms of Service</a> | <a href="">Privacy Policy</a>
<div class="fork span-7">
This website is <a href="">open source</a>.
Please help us by forking the project and adding to it.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "' type='text/javascript'%3E%3C/script%3E"));
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3769691-2");
Jump to Line
Something went wrong with that request. Please try again.