GIT Tutorial: Maintain your project easily


08 Mar  

In the last edition, I tried to elucidate the point that GIT is the most efficient source management tool for open source projects. In this edition, I will illustrate how to implement GIT and create a GIT repository for your project.

Please note that I’m going to use one of the Java programs that I wrote a few months back (It is a Java web application that uses Spring, Hibernate frameworks and DWR tools. But you don’t require knowledge in Java for doing this tutorial.).

 

Installing GIT in your system

Since GIT is very popular you can easily install it using an standard install command (specific to your distribution). You may also look at the distributions repository to check that the software is available. In my system (Ubuntu) I used:

 

sudo apt-get -y install git-core gitosis

 

This will install the GIT core and the gitosis package. Fedora users may try ‘yup’ and OpenSuse users can find this in the YaST2 listing. If everything fails, try installing from source.

Once you have installed the software, you can add the project to it. First of all, go to the directory where the tarball (source code) of the project is located and then untar it to the directory.

 

aasisvinayak@GNU-BOX:~/Desktop/git_tutorial$ tar xzf Java_app.tar.gz

aasisvinayak@GNU-BOX:~/Desktop/git_tutorial$ cd Java_app

 

Now initialize GIT to create an empty git repository and GIT will inform you that the directory has been created:

 

aasisvinayak@GNU-BOX:~/Desktop/git_tutorial/Java_app$ git init-db

Initialized empty Git repository in /home/aasisvinayak/Desktop/git_tutorial/Java_app/.git/

 

Now, GIT will again ask you to add your first commit statement (default) after adding the files.

 

GIT commit

 

You may add your own custom commit line in the editor and save the file.

 

GIT - add commit comment

 

Now you can see that GIT is creating modes and adding ‘files’ to the ‘master branch’.

 

GIT - adding file to repo

 

You may install ‘Giggle’ in order to view the GIT graph.

 

GIT  using Giggle 

 

Tracking Changes in GIT

Edit a particular file in the project and add one or two files to it (for testing).

In my case I’m going to use ‘GamesScheme.java’.And as you can see I have added a comment line for testing.

 

GIT  testing

 

Now I need to issue the following command in order to add the edited file to the repository.

aasisvinayak@GNU-BOX:~/Desktop/git_tutorial/Java_app$ git add ./src/java/esd/cw/model/GamesScheme.java

 

If I want to see the change, I can simply issue:

git diff  –cached

 

And I could see the difference:

GIT - tracking changes

 

After reviewing the difference and  I need to issue

aasisvinayak@GNU-BOX:~/Desktop/git_tutorial/Java_app$ git commit

 

This command will allow me to finalise my changes and add that to the branch in which I was working (master). I can also add the ‘commit’ comment at this stage.

 

GIT  - changes - commit comments

 

It will also summarise the changes:

 

[master f199bc0] tested GIT techblog.aasisvinayak.com

1 files changed, 1 insertions(+), 0 deletions(-)

 

Now this will also be visible when you see the graph structure.

 

GIYT graph view

 

And when you browse through the source code using Giggle, you can actually see the changes (along with the name and details of the person who added the code).

 

GIT - in giggle - source 

 

There are various other GUI tools which you can try out. Here is another one:

 

GIT GUI

 

Maintaining an online repository

 

You have two choices here:

  • Install GIT in your server and manage it from there
  • You can host that in a public server like Gitorious

 

In these cases, you need to configure some global setting for GIT. In my case I need to add:

aasisvinayak@GNU-BOX:~$ git config –global user.name  "Aasis Vinayak"
aasisvinayak@GNU-BOX:~$ git config –global user.email
aasisvinayak@gmail.com

 

The only difference in this case is that the you need to use your RSA/DSA key each time you connect to the server and you may have to add the GIT URL along with the commands.

For example, if you want to pull the repository you may use:

git pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

(You can use ‘git clone’ for getting the source)

For switching to master you can use

git checkout master

Then make the changes by issuing:

git remote add origin git@yourdomain_name.com:sample-java-project-for-techblog/sample-java-project-for-techblog.git
git push origin master

 

We will be covering more GIT commands and tools in the ‘Kernel Dev’ section.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Tags: , ,


TechBlog on Facebook

Comments (2)

 

  1. Dscho says:

    You might want to mention that your EDITOR is set to nano (which is not the case everywhere), and you might want to replace the call to “git init-db” by a call to “git init”…

    Otherwise, pretty and nice, and easy to follow!

  2. [...] and scheduling  the tasks. As you might be knowing, this [...]'; digg_skin = ''; In the earlier edition , we discussed about GIT and found that the tool is extremely reliable for managing the source code [...]

Leave a Reply