Monday, 6 August 2012

Git Basics


Git Basics.
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is a powerful DVCS. Git has unworldly powers.
Some of the advantages of Git over other VCS are:
  • Since the entire history of the project right there on your local disk,
    most operations seem almost instantaneous.
  • If you want to see the changes introduced between the current version of
    a file and the file a month ago, Git can look up the file a month ago and do
    a local difference calculation, instead of;
     Either ask a remote server to do it.
    Or pull an older version of the file from the remote server to do it 
    locally.
  • You can do much of your work when you are travelling or when the VPN
    client is not working properly , you can then commit happily when you get
    to a network connection to upload.
  • Everything in Git is check-summed before it is stored and is then referred
    to by that checksum. This means it’s impossible to change the contents of
    any file or directory without Git knowing about it.
  • You can’t lose information in transit or get file corruption without Git
    being able to detect it.
  • The mechanism that Git uses for this checksumming is called a SHA–1 hash.
  • Git stores everything not by file name but in the Git database addressable
    by the hash value of its contents.
  • Git has three main states that your files can reside in: committed,
    modified, and staged.
               Committed: Committed means that the data is safely stored in your
                                  local database.
               Modified: Modified means that you have changed the file but have not
                                committed it to your database yet.
               Staged: Staged means that you have marked a modified file in its
                            current version to go into your next commit snapshot.
  • The basic Git workflow goes something like this:
        1. You modify files in your working directory.
        2. You stage the files, adding snapshots of them to your staging area.
        3. You do a commit, which takes the files as they are in the staging
             area and stores that snapshot permanently to your Git directory.
  • Hence, If a particular version of a file is in the git directory, it’s
    considered committed. If it’s Modified but has been added to the staging
    area, it is staged. And if it was changed since it was checked out but has
    not been staged, it is modified.
How to start with Git.
First thing is to install it. You can either install it from source or install an existing package for your platform.

 * If you’re on a Debian-based distribution like Ubuntu, try apt-get:
               '$ apt-get install git-core'
 * Next step is to 'First Time Git Setup' to personalize the git
 * For this you have to create a Repository in github.com/
 * Once you had created the Repository, then open the terminal,the folder where the code is saved, that         is to be pushed to github repository.
 * Then do the following steps:
  • 'git init'
               # To initialise.
  • 'git add filename'
               # To add a file (Eg: git add string.py).
  • 'git commit -m "first commit"
           # To commit the file with version number. if the edited second version    is pushing, then do "second commit".
               # To push the code directly to the repository from terminal. Master is the name of computer and the url is obtained when the repository is created in Github.com.
               #Then enter the username of github(Eg: 'kishorekdty').
               #Enter your password of github and press enter key.
  • Thats all to do..
             Then it will show something like;
             To https://github.com/kishorekdty/kishore.git
              25192b3..23ee338 master → master
              So your code has pushed to Github..


1 comment: