Product SiteDocumentation Site

3.3. Git

Git is a version control system that was not written to improve on CVS and SVN but rather in retaliation to them. Git was created with four design points in mind:
  1. Not like CVS and SVN. Torvalds, the creator of Git, does not like these programs and wanted to make something that was unlike them.
  2. Support a BitKeeper-like workflow. The way a project is managed ideally follows the same process as BitKeeper, while keeping its own design and not becoming a BitKeeper clone.
  3. Strong safeguards against accidental or malicious corruption.
  4. Very high performance.
To accomplish this, Git approaches how it handles data differently to its predecessors.
This section will go through the most common processes in a day's use of Git.
Previously the version controls covered (CVS and SVN) treated data as changes to a base version of each file. Instead, Git treats its data changes as separate snapshots of what the files look like and stores a reference to that file (though if the file remains unchanged, Git will simply store a link to the previous identical version rather than copy another file). This creates a kind of new mini-filesystem. The image below compares these concepts visually:
Git version control
Figure 3.1. Git version control

Git is particularly fast, something that is aided by not needing to constantly connect to a remote repository. The snapshot nature of Git and how all versions are stored on the local file system means that nearly everything can be done without connecting to any kind of network and the history of the project is available locally.
To fulfill Torvalds' integrity requirement, everything in Git is check-summed before being stored and then referred to by that check-sum. This means the contents cannot be changed without Git's knowledge and information cannot be lost in transit or corrupted. A SHA-1 hash mechanism (a forty-character hexadecimal sting) is used for this.
In addition, there is very little in Git that cannot be undone. This is aided by the three main states a file can reside in.
Committed
Data is safely stored on the local database, and unchanged.
Modified
The file has been changed but not yet committed to the database.
Staged
A modified file has been marked to be committed in its current version.

3.3.1. Installation

Git can be installed either from source or from the console. If the user is confident enough then the recommendation is to install from source, as the binary installers don't always have the most up-to-date version available.
To install Git from source code, use the following procedure:
Procedure 3.2. To install Git from source code
  1. Install the libraries Git depends on: curl, zlib, openssl, expat, and libiconv.
    $ sudo yum install curl-devel expat-devel gettext-devel \
    openssl-devel zlib-devel gcc
    
  2. Download the latest snapshot from the Git web site, located here: http://git-scm.com/download.
  3. Compile and install.
    $ tar -zxf git-1.7.6.1.tar.gz
    $ cd git-1.7.2.2
    $ make prefix=/usr/local
    $ sudo make prefix=/usr/local install
    
  4. It is now possible to get updates for Git, from Git.
    $ git clone git://git.kernel.org/pub/scm/git/git.git
Installing Git with a binary installer from the console is as simple as using the following command.
$ yum install git