Sunday, April 10, 2011

GIT -New generation Source Code Version Control

What is Git?
 
         Git is a open source revision control software developed by Linus Torvalds to manage LinuxKernel Developement.Git development began after many Linux kernel developers chose to give up access to the proprietary BitKeeper system. The copyright holder of BitKeeper, Larry McVoy, withdrew free use of the product after he claimed that Andrew Tridgell had reverse-engineered the BitKeeper protocols.and this eventually led to birth of Git ,which is a fast, scalable, distributed revision control system with an unusually rich command set providing both high-level operations and full access to internals.

         It is written in a collection of Perl, C, and various shell scripts, based on the needs of the Linux kernel project; decentralized , and aims to be fast, flexible, and robust.


 GIT Usage:

       Git Usage in opensource community  is picking up pace as most popular opensource projects have started to use it as a primary revision control software.
Android,meego,linux kernel,Qt,Kde,etc
So for all those who are out to support the opensource community,u must be a real master of this tool ,So lets begin ......
 
Installation:

            Binaries are available in the following link : http://git-scm.com/download
based on the OS download the  binaries and install them respectively.

            But the best and easiest way would be downloading the source as tarball and compiling it .
Here are the steps:

     1)Download the Source from http://kernel.org/pub/software/scm/git/git-1.7.4.4.tar.bz2.

    2)Untar the tarball source

$ tar -jxvf git-1.7.4.4.tar.bz2
   
    3)Change to the appropriate directory and issue the command  'make'
   
(note: Gitcore is dependent on the following libraries libcurl,zlib,libcrypto,rsync so see that these libraries are present before trying to build the git source)
                
$ cd git-1.7.4.4/
$ make prefix=/usr/local install
$ sudo make prefix=/usr/local install
 
               
After the successful installation you are permitted to use the Git tools.

With this installation we can use git only using the commands,ie only with the help of terminal,inorder to use git with ui we need to install any one of the available frontends like  qGit,gitx,gitk etc.

FrontEnds  or the Gui really come in handy when trying to check the history,difference between the versioned files,etc.

 Exploring Git -

Lets create a repository of Linux kernel in our Local pc and start using it with basic available git commands.

1)Creating a Local repository
 
$ mkdir linux-2.6
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6
if the provided mirror git link is valid,then we can see the following info on the standard output
    
 
         $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6
            Initialized empty Git repository in /home/avinash/rnd/linux-2.6/.git/
            remote: Counting objects: 21292000, done.
            remote: Compressing objects: 100% (6111000/6111000), done.
            remote: Total 21292 000(delta 16697000), reused 19111000 delta508500)
            Receiving objects: 100% (21292/21292), 9.65 MiB | 10 KiB/s, done.
            Resolving deltas: 100% (16697000/16697000), done.

above step fetches git object along with the source code,which actually keeps track of the source files and the version information.

2)Updating your local Git repository
      
         we usually tend to update our repository to recive the latest changes that was done by other opensource developers.So it is always good to have the latest updated upstream source tree, this type of updating is referred as fast-forward merge


$ cd linux-2.6
        $ git-pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
output on successful execution of the above command
 
receiving file list ... done
         sent 130 bytes  received 11677 bytes  185008.00 bytes/sec
         total size is 237865858  speedup is 5863.52
         Already up-to-date.
        $>

3)Checking files out of the repository
 
   checking out is the act of creating a local working copy or branch from the repository. A user may specify a specific revision or obtain the latest.
to do this we need to use the following command
             
$ git-checkout
 
    if we need to overwrite any of our local modification we can do this by issuing a checkout with -f option to bring back to original form.

     
$ git-checkout -f
          
    In order to view the various branches of the repository we can use the following command

           $ git branch
*master
 
    A freshly cloned repository contains a single branch head, by default named "master", with the working directory initialized to the state of the project referred to by that branch head.

         
$ git tag -l
 
    It will list all the tags used by the project(Tags are references into the project’s history)
 
4) Modifying existing files 
   i) Altering the files and commiting it to the repository is very simple.
Just modify the file which ever you are intended to and issue the following command to the modified file. 
$ git commit  filenamewithpath 
 
$git commit would  prompt the user to provide commit message,which will be useful for other developers
to know what changes were made and their purpose.So it should be a good practice of adding the commit 
message in a precise way.
  
ii)Adding files to the repository                         
 
$ git add file1
 
multiple files can also be added
 
         $ git add file1 file2 file3 
 
This file snapshot is now stored in a temporary staging area which git calls the "index". You can permanently store the contents of the index in the repository with git commit
$ git commit.
 
iii)Removing files can be done with no specific command like adding just deleting and 
issuing commit command will remove the deleted files from repository or using 
$ git rm filename 
will remove files from the working tree and from the index.       
   
 
 
4)Other Basic commands
 
$ git log   -At any point you can view the history of your changes
$ git diff  -show chnages between comits,commit and working tree etc
$ git fetch -Download objects and refs fro another repository
$ git pull  -fetch from and merge with another repository or local branch
$ git push  -update remote refs along with associated objects 
$ git init  -create an empty git repository or reinitialize an existing one
$ git merge -join 2 or more developement histories.
$ git status-shoes working tree status.   

No comments:

Post a Comment