Sunday, August 16, 2009

GIT Tutorial

Hey guys and gals,

This is my version of tutorial on Git.

I won't go into much details of what git is all about, though you can always go here to have a look, git tutorial, which is actually an excellent boot up guide to Git and it's advantages. To be very precise Git was developed by Linus Torvalds to manage the Linux Kernel Tree and it turned out that Git is presently the best Version Control system on paper and in implementation!

Public and Private Repositories

Repositories are the place where you actually keep your source code. So that a person who wishes to have a look at your code in a programmer friendly way! Also it is used to do collaborative coding, while maintaining an Organizational Hierarchy, it is equivalent to a management system built into the haphazard world of Open Source :).

Public repositories are the repositories which everyone can have a look at. Generally Repositories are public so that anyone can have look, open source needs to be open ;). But the ability to write to a repository still lies in the hands of "the" few from the Circle of Trust.

Private repositories are different in the sense that you can't have a look at the code it u aren't a part of the project, private repositories are rare... though they exist.

Starting a Basic Project in Git

There are a plethora of excellent tutorials that tell you how to use git, and I won't try to reinvent the wheel. Though here's something important to note. As Git is meant for collaborative work, you check out code from some remote host( repos ) and then make local changes, and then push it back to the remote repository. First thing you need to learn is to use Git in the local system. I would suggest you to go through the following texts.

0. Use a Linux Box if you may. Windows users should look at this: windows link. But try to use a linux box because it'll be easier to get help :).

1. Official Git Tutorial - A great place to start, follow the exact steps uptill the point you can pursue. Try to read upto the section: Managing Branches, and yeah work each command on your machine.

2. Those familiar with svn should look at this

3. Once you've dealt a fair deal with using git locally it's time to dive into some Remote servers.

Web View of Git Repository

If you are familiar with version control you might be aware of Web Views for common Version Control services. Familiar are Github, Google Code. You can visit these site and look at an arbitrary project and have a feel of the Repositories. I have maintained my own version of Git Server and the Web Views can be looked up from here. We'll be using this for the rest of the tutorial so make sure you are able to get it work!

http://maillist-cse.iitkgp.ernet.in/viewgit/
or
http://203.110.246.113/viewgit/

Note:- To use the maillist-cse.iitgkp.ernet.in Link please use 144.16.192.247 as your proxy and while using the second link you don't need to change your proxies :).

So you can see a free_monkey repository. It's just a test repository containing some of my interesting source code ;).
Things to watch out for( make urself familiar, now is the time ):

1. When you enter the repository you can see, Shortlogs, Tags and Heads. Shortlogs are the commits that coders do on a repository. Something like you make a local change and push it to the remote server.

2. There are two heads, master and experimental. These are the branches that exist for the code. A single project( code ) can have multiple, non interferring, branches.

3. Some hyperlinks above show a Tree link, which is the listing of code.... the stuff inside ;).

Heads

Heads are the branches of the code. Suppose you wish to work with me on this project, so instead of working on the master copy( which is a compulsary branch ), I would ask you to start your own branch and start commiting there. In our case we have the master and experimental.

You can switch the Code tree for any branch from these links.

Checking out Code

As this repository is public, you might wish to check code to have your own copy to work with. These are the steps you need to do.

First of all, git runs on a ssh service, and as port 22 is blocked in Institue. I am running this server on 4545 port. In a standard ubuntu box you will have to make the following changes:

$ sudo vim /etc/ssh/ssh_config

Search for a line which says "Port". Uncomment it and write: Port 4545. So the section now looks like:

# IdentityFile ~/.ssh/identity
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
Port 4545
# Protocol 2,1
# Cipher 3des

Cool! Let's move further. You now need to clone the public repository into your computer. Do the following steps.

$ mkdir git # Make a folder for git repositories
$ cd git
$ git clone git://203.110.246.113/free_monkey/
Initialized empty Git repository in /home/user1/git/free_monkey/.git/
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 34 (delta 7), reused 0 (delta 0)
Receiving objects: 100% (34/34), 42.23 KiB, done.
Resolving deltas: 100% (7/7), done.

Voila! We have got our own copy of Git source. These are the interesting things that you might wish to do:

$ cd free_monkey
$ git branch -a
$ git checkout experimental
Note: moving to 'origin/experimental' which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD is now at 878804d... Graph for activity logger

If you are done till here, watch ourt for the next iteration of git tutorial. Any doubts, please reply here :)!

No comments:

Post a Comment