How to install and configure Git to manage source code

Git is an open source, distributed version control system with the emphasis on being fast. It was developed by Linus Torvalds for managing Linux Kernel. It was primarily focused for Linux, but now its available for almost every operating system. Its fast on POSIX-based systems such as Linux. Its different from SVN because it creates a private repository on remote server as well. Some projects using Git -  Linux kernel, YUI, Fedora, Debian,, VLC, Perl, there is some work going on to shift Drupal on Git too.

Installing GIT on Fedora and Ubuntu

Lets start by installing Git and Gitweb, a web interface for Git.

[root]# yum install git-core gitweb       #For Fedora/RedHat based Distros

[chia]$ sudo apt-get install git-core gitweb  #For Debian or Ubuntu based distros

Configure Git

First thing you want to do is set up you username and email address. GIT uses colour to notify user about the crucial things so we need to activate colors as well. The following commands will do that for you.

[chia]$ git config --global "Tushar Mahajan"

[chia]$ git config --global ""

[chia]$ git config --global color.status auto

[chia]$ git config --global color.branch auto

Using --global will apply it at global level. It will store the information at .gitconfig in your home directory.

[chia]$ cat ~/.gitconfig

You can check the values by using:

[chia]$ git config

Now we are all set up, we need to create a Git repository.

[chia]$ mkdir project

[chia]$ cd project

[chia]$ git init

Initialized empty Git repository in /path/to/project/.git/

Now you can see there is a .git directory inside the project.

Add some description to the project:

[chia]$ echo "Short Project Description " >  .git/description

Git stores its actual compressed objects in .git/object directory.

It will be empty at this point of time.

[chia]$ git add .    # git add is used to add file contents to the index.

# To check what is there in the index files run

[chia]$ git ls-files

[chia]$ git ls-files --stage # this will display all the sha checksums of the indexed files.

[chia]$ git status

[chia]$ git commit

"git status" will show a list of all the new and updated files that are there in the directory.

Add all the files to the repository by using "git commit". Now running "git status" will show

# On branch master

nothing to commit(working directory clean)

To show the latest commit messages:

[chia]$ git log

Cloning GIT directory

You can clone git directory using either git protocol or using http. Git works on port 9418.

# Clone using git protocol

[chia]$ git clone git://

# Clone using http protocol

[chia]$ git clone

# Git protocol is more efficient for cloning. But in the end you will get same thing.

Now, we have successfully installed and configured Git on our system.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.