Vishwanath Krishnamurthi's blog

A blog on Java EE, clean code, open source and TDD

What cool things can you do with GIT ?

with 6 comments

A “Distributed Version Control System” (DVCS) has so many fascinating things to offer. And it’s no wonder the world is moving towards this fascination.

Of the so many possibilities a DVCS has to offer, there are two that I like a lot.

Read on, to see what…

1 ) Make reusable project skeletons:

I have a project, that I push to a repository. Then I make some changes. Now the new changes, I can push them to a new repository (instead of affecting the old one )


What’s so cool about it ?ย  See this –

As a part of the initial project setup I add junit and dbunit libraries, say… Then push the changes to a repository. Then I make some changes, to make it a hibernate project. Instead of pushing it to the old repository, I push these to a new repository, as shown below

What this lets me do is, create different junit+dbunit projects by cloning the test-skeleton project !

Like this –

There are a lot many times, when I have wanted to try-out some code, but being too lazy to configure , I give up.

Now with project skeletons created, I can reuse them, and fork them to different shapes ๐Ÿ˜‰

And what’s the best part ? If at any time I make changes to test-skeleton,( say I add logging-api) I can pull those changes to any of the projects I had cloned and modified !

2)ย  You don’t have to push to central repo, to share your partial changes !

Normally with a centralized repo, this is how we share our changes :

And likewise in a DVCS (say git )

Say I have written some code. It’s not completely tested though.ย  Developer-B needs this, for his work to start.ย  The rest of the world does not need it immediately ! So how can I share it to developer-B and not to developer-C,D,…Z ?

It’s just as simple as this :

developer-B configures your repository as a remote-repository and pulls changes !

With a command that looks like this (For windows)

git pull \\<your-ip>\shared_directory\<your-repo>

Well, that’s it, in this post. The more you explore git, the more you realize of its power ! Join the exploration ๐Ÿ˜‰

Written by Vishwanath Krishnamurthi

May 12, 2011 at 8:04 pm

Posted in Tools

Tagged with , , ,

6 Responses

Subscribe to comments with RSS.

  1. nice post that gives an introduction to git and trigger to learn it

    sivaram

    May 14, 2011 at 9:16 am

  2. Great Vishwa. Keep up the good work. Though I’m not using GIT at the moment, this would be a good tutorial in future. I will bug you then as well.. ๐Ÿ˜€

  3. “If at any time I make changes to test-skeleton,( say I add logging-api) I can pull those changes to any of the projects I had cloned and modified”

    I am a Git “noob.”

    How would I go about doing something like this?

    Jeremy

    June 29, 2011 at 7:06 pm

  4. Hi Jeremy,

    Say I have cloned test-skeleton project, in a directory “concreteOne” with this command –

    git clone remote-url-of-testSkeleton

    When the cloning is completed,

    git remote -v

    would list the remote repo associated with this.

    It would look something like

    origin remote-url-of-testSkeleton (fetch)
    origin remote-url-of-testSkeleton (push)

    That means that I can fetch/push.

    The cool thing is that I can add more remotes,

    git remote add aShortName a-different-remote-url

    (I’ll create one with a shortname ‘cname’ )

    Now when we list the remotes using “git remote -v” it would look something like,

    origin remote-url-of-testSkeleton (fetch)
    origin remote-url-of-testSkeleton (push)
    corigin a-different-remote-url (fetch)
    corigin a-different-remote-url (push)

    This means that I can fetch or pull from any of these listed remotes.

    I can now change the cloned project to something concrete (say hibernate project ) and push it to corigin instead of origin

    git push corigin master

    If testSkeleton project has had some changes, I can take it here by,

    git pull origin

    In short, its all because of the ability to “add multiple remotes easily”


Leave a reply to sivaram Cancel reply