how to install and configure git

Sarath Pillai's picture
installing and configuring git

Installing Git

Hi all, i will begin this post from where i stopped the Introduction to git. We will first have a look at the three main states of a file in GIT version control system.

Note:  This three main states needs to be understood very carefully.

Git has got three main states, in which files will be. they are as follows.

  1. committed
  2. modified
  3. staged

Commited

commited means, that the changes you have made to a file, is stored in the git database.

Modified:

modified means that you have changed or edited the data, but is yet to commit to the database.

Staged:

Staged means that you edited some files, and have marked them to go the database in the next commit.

 

Basically git work flows like the following steps.

Step1: You changed the files in your working directory

Step2:Stage the files, for the next commit

Step3:Commit, during this commit the files is taken as it is from the staging area and stores it as a snapshot in in the git directory.

Note: Dont worry if you dont understand some term here...you will be able to grasp it easily as you move on with this documentation. Any doubts regarding this document is welcomed.

now lets go ahead with installation of git.

Inorder to install git, you require the following packages, if you already have these packages then its fine, otherwise you can install them as shown below.

[root@myvm1 ~]# yum install curl-devel expact-devel gettext-devel openssl-devel zlib-devel

Now you can either install from source of binary. I would suggest installing from binary(as shown below).

Note:  Source package is available for download from http://git-scm.com/download

Now you can install git by using yum package manager.

[root@myvm1 ~]# yum install git-core

Note: You need to have rpmforge repository enabled on the machine for installing git with yum.

Installing Git on Windows:

You can download git exe for windows from http://code.google.com/p/msysgit/.

Simply running the intaller will do the trick for windows machines. The git exe in windows will install a command line and a gui GIT.

Configuring GIT:

git config tool that comes along with git will be helpful in setting up git configuraton variables. And there are three possible locations for these variables to be stored. they are as follows.

/etc/gitconfig:  this file contains values for all users in the system, and their respective repositories.

~/.gitconfig: this is the user specific git configuration file

.git/config: specific to a repository

configuration options in the config file of a specific repository will override all other options. for example .git/config will override /etc/gitconfig

Before going ahead with the configuration options in git. You first need to create and initialize a git repository. This can be done with the following command(the directory where you run the below command, will be your git repository.)

[root@myvm1 yum.repos.d]# pwd
/etc/yum.repos.d
[root@myvm1 yum.repos.d]# git init
Initialized empty Git repository in /etc/yum.repos.d/.git/
[root@myvm1 yum.repos.d]#

In the above shown example, /etc/yum.repos.d/ has become your git repository.

The first configuration we must do while working with git is to set your user name and email address. This is very much important to track all the events in the git version control system. Each and every commit will contain your name and email address.

setting the username and email address can be done through the git config command(but before running these commands, in any directory, you need to first initialize your repository as shown above).

[root@myvm1 ~]# git config user.name "Sarath"
[root@myvm1 ~]# git config user.email "sarath@example.com"

now the above command will set user name and mail address for a specific repository, (but you need to be inside that project directory)

If you want to set user name and email address for all the projects in a system then you will need to pass the option --global with the above command(for doing this you do not require any git repository, because config options are going to be saved inside global config files).

example: git config --global user.name <username>

git config --list will show you all current configurations.

git config help will list all commands with config option.

Hey dont worry!! we still have not started version controlling with git!!!smiley.. We will continue this tutorial with some indepth git basics,setting and getting a repository,cloning a repository etc.

thank You all...

Rate this article: 
Average: 5 (3 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
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.