Sunday, 23 June 2013

GIT : distributed version control, getting started

Posted by Unknown
git tutorial, git distributed version control, git getting started

Git is a distributed version control and Source Code Management (SCM). Git was initially developed by Linus Torvalds for maintaining Linux Kernel development. Git is largely inspired by BitKeeper and Monotone distributed version control. Git is entirely developed in C. Though Git is developed on Linux it is also supported for different operating such as Microsoft Windows, Solaris, Mac OS X.

One can install Git on Redhat/CentOS through yum using the following command:
$ yum install git

On ubuntu and debian based systems  :-->  $ sudo apt-get install git

Creating Git repository :

For creating Git repository, suppose your source code is in some folder named "all_src".
Then you need to go in that directory that is "all_src" in our case type the following command

$ git init  

this will create a git repository in that directory and you can start using other git commands on your created repository.

Basic Branching in Git 

A single git repository can maintain several branches of development. To create a new branch named "experimentation", use
$ git branch experimentation
If you now run
$ git branch
you'll get a list of all existing branches:
* master
The "experimentation" branch is the one you just created, and the "master" branch is a default branch that was created for you automatically. The asterisk marks the branch you are currently on; type
$ git checkout experimentation
to switch to the experimentation branch. Now edit a file, commit the change, and switch back to the master branch:
(edit file)
$ git commit -a
$ git checkout master
Check that the change you made is no longer visible, since it was made on the experimentation branch and you're back on the master branch.
You can make a different change on the master branch:
(edit file)
$ git commit -a
at this point the two branches have diverged, with different changes made in each. To merge the changes made in experimentation into master, run
$ git merge experimentation
If the changes does not conflict, its is done. If there are conflicts, markers will be left in the problematic files showing the conflict;
$ git diff
will show this. Once you've edited the files to resolve the conflicts,
$ git commit -a
will commit the result of the merge. Finally,
$ gitk
will display a good graphical representation of the resulting history.
At this point you could delete the experimentation branch with
$ git branch -d experimentation
This command ensures that the changes in the experimentation branch are already in the current branch.
If you develop on a branch test-idea, then regret it, you can always delete the branch with
$ git branch -D test-idea
Branches are less expensive and easy, so this is a good method to try something out.

These are basics to get started with Git, different features of Git will be posted in forthcoming posts. 


1 comment:

  1. Good explanation for the beginner like me. Thanks for the article