Tuesday, March 30, 2010

Git with SVN by Praveen MV

For the uninitiated, Git was invented by Linus Torvalds to support the development of the Linux Kernel, but it has since proven valuable to a wide range of projects. There are two git packages for windows: Cygwin based git and msysGit.

Git concepts

Repository: An archive of what the working tree looked like at different times in the past — whether on your machine or someone else’s. It’s a history of snapshots, and allows you to compare your working tree to those past states.

The index: Git does not commit changes directly from the working tree into the repository. Instead, changes are first registered in something called the index. Think of it as a way of “confirming” your changes, one by one, before doing a commit (which records all your approved changes at once).

Working tree: Any directory on your file system which has a repository associated with it (typically indicated by the presence of a sub-directory within it named .git.). It includes all the files and sub-directories in that directory.

Branch: Just a name for a commit, also called a reference. It’s the parentage of a commit which defines its history, and thus the typical notion of a “branch of development”.

Master: The mainline of development in most repositories is done on a branch called “master”. Although this is a typical default, it is in no way special.

HEAD: HEAD refers to the most recent commit of the last branch you checked out. Thus, if you are currently on the master branch, the words master and HEAD would be equivalent.

Getting started

Lets start of by seeing how we can checkout exisiting repository , make modifications and check in .Checking out repository is as simple as :

git svn clone
This might take a long time based on how old the codebase is . It gets information of every thing that happened on the repository , all the logs etc .
However the simplest and fastest way to check out exisiting repository is to copy .git folder from any one who has code checked out. Using git bash, navigate to folder containing .git folder and execute the following command

git checkout
Now we are ready with our local repository .
Next as developers we modify the code, add new feature . Now we need to commit . So lets see how to commit a code . Use the following comand to view the modification made to the source code.
This comand shows all the new and modified files .

git status
Now we need to add all the new and modified files to list of files to be committed . Use the following:

git add .
We can also add one file at a time using

git add filename
Now we must commit the file added to our local repository

git commit -m "Message while commiting"
So far we have commited to our local repository . Now we must take updates from the main repository to see if there are any modification or confilicts .

git svn rebase
This gets the latest files from the repository and updates the modification made by you on to the latest file .Assuming there are no confilicts. Now we can commit our code to the central repository .
so we run

git svn –dcommit
We are done with our first commit .We have covered the basic flow of git .