Harry Seldon's blog

Fractals, Chaos, and Control Systems on Rails

Read

Grand Gardening with GIT

Posted by Harry Seldon on November 08, 2008

Why is GIT so interesting ?

With git, I have been doing some gardening these days. Indeed I growed trees, cut branches, grafted branches.
I have been using a Version Control System (VCS) only for one year. That is about since I started the Thinkosphere project. I have been using SVN. At first I was like “Hey this is so cool”. SVN is a real time machine or at least a past time machine. You can easily go back in time to get the state of your source code from months ago. Unfortunately you cannot go forward to the future (with GIT you will be somehow able to do that !).

So after the honeymoon with svn, I began to find some limitations. Mainly I was missing an easy way to have two repositories talking to each other. Let’s see why. Here is a concrete example of how a Distributed Version Control System (DVCS) can be useful. This blog is powered by Typo which is open source. I downloaded the source code and I put it into a repository of mine to be able to make some minor changes (for instance these ones). But doing this I lost the connection with the original repo. That means I cannot easily upload my changes to the “main” repo neither can I go forward in time by downloading the last changes on the main repo.
This is exactly the kind of situation which git was designed for. Indeed with git the various repos can easily communicate with each other. So I can merge the latest updates from the main repo to my own local repo.

Tutorial

Let us see the setup of such a configuration in details. I will not use the example of this blog because it is still theoretical as I have not migrated it to git yet. Instead, I will use the exact configuration I am using to contribute to Open Flash Chart plugin and its test app.
Notice the setup is well explained in the excellent GIT User’s Manual at this chapter from which I am taking the following graph:

                      you push
your personal repo ------------------> your public repo
      ^                                     |
      |                                     |
      | you pull                            | they pull
      |                                     |
      |                                     |
      |               they push             V
their public repo <------------------- their repo

Let us go over the steps. Imagine you want to download OFC test app, you want to make your own modifications while being able to regularly download the updates and you also want to upload your changes.
For the configuration resulting from the following tutorial, I can precise this:

  • your personal repo = local repo = repo on your computer = repo in your working copy
  • your public repo = repo on github, mine is here
  • their repo = repo on PullMonkey’s computer
  • their public repo = ‘official’ repo = repo on PullMonkey’s github

Let me precise also some GIT Vocabulary :

  • To upload your changes from a repo to a repo is to push.
  • To download your changes to a repo from a repo is to pull (to be precise pull fetches the changes and merge them to the current branch).
  • To upload your changes from your working copy (or working tree) to your repo is to commit.
  • To download changes from your repo to your working copy is to checkout (checkout command is also a simple command to switch between branches).
  • Downloading a repo to create a repo : clone.

First, your fork the public repo to a public repo of yours: You go there you click on fork. (you will need a github account)
Then you download (clone) your repo to your local repo :

git clone git://github.com/pullmonkey/ofc_test_app.git

(It both creates the repo and checks it out)

Now you make some changes. You commit them:

git commit -a -m "my changes"

You want to upload your changes to your public repo:

git push

You want them to take into account your changes. You send them a pull request through email or github.
They agree to try it, they pull from your repo to their repo. They love it. They push it to their public repo.

They also made some more changes. You want to get them.
The first time you need to add the address of the public repo:

git remote add their_public_repo git@github.com:pullmonkey/ofc_test_app.git

Then, here is the GIT’s beauty, you pushed to a repo but you pull from another repo:

git pull their_public_repo

You can add as many repos as you want. You can see all these repos from a part of the global tree of the application development. Each repo is a tree branch. More than that each repo can contain several branches. Each branch can have a purpose: development, test, release etc. So have a happy gardening and happy time travels with git !

Any mistake, any problem or everything works ? Leave a comment !

Git resources:

Bonus

As I am a private pilot, all this push/pull stuff made me think about the push/pull aircraft :

Notice it has two propellers aligned with the fuselage one to pull and one to push.

Posted in | 8 comments | Tags , , , , , | atom

Delicious

Trackbacks

Use the following link to trackback from your own site:
http://harryseldon.thinkosphere.com/trackbacks?article_id=24

  1. There will be war, or, how to prevent it From Harry Seldon's blog
    For some time, I have wanted to post about "crises are natural preludes to wars". I am definitely not that qualified to say that, so [I am glad these guys (LEAP experts) are](http://www.leap2020.eu/English_r25.html). They predicted quite well the ...

Comments

Leave a response

  1. Brent on November 13, 2008 at 01:39 am

    Best Post on Git I have read so far thx,

  2. Harry Seldon on November 13, 2008 at 10:05 am

    Thanks Brent, I am glad you liked it.

    About more advanced subjects with Git, here is a nice post: Easy Git External Dependency Management. I guess I will blog about git submodules and giternal at some point too.

  3. Brent on November 15, 2008 at 04:03 pm

    Thx for the link Decided to go with Braid

    installed nofxx’s : annotate_models

    braid add git://github.com/nofxx/annotate_models.git -p

    Modified it to not change the schema number for every migration (annoying).

    checked in the change to my repository

    Seems to do everything I need at the moment and very well.

    Will checkout giternal if I have any problems.

    Even though gems are in, I don’t really like their global nature, If I am running multiple projects using different gems how do I know which ones to freeze at deploy time?

    Can’t believe I have only been using git for 2 days. Thx to all the people contributing to quality posts and plugins.

    If your doing Rails change to git its easy.

    I especially like the git diff. under subversion I was always: svn diff | view -

    I also follow the commit as often as possible pattern, but if you use CI this is sometimes a pain, being able to commit all my small changes and then push is great.

  4. Harry Seldon on November 15, 2008 at 06:48 pm

    Thanks for the info. I will check Braid too. I have quite a few things left to learn :

    • git and external dependencies
    • git and ssh (installing a remote repo on a regular server, not github)
    • git and capistrano
    • git and svn migrating a repo from svn to git
  5. Harry Seldon on January 10, 2009 at 03:25 pm

    A nice article about git on a shared host.

  6. Harry Seldon on January 23, 2009 at 07:56 pm

    As promised, here is a post about:

    • git and submodules
    • git and Typo
  7. Gardening Seeds on February 25, 2009 at 11:00 pm

    Thank you very much for the information I really appreciate it!! I found this useful site for Gardening Seeds

  8. Harry Seldon on February 26, 2009 at 08:28 pm

    Previous comment looks like a spam. But it is so funny that I keep it.

Leave a comment

Markdown enabled




Search

Navigate


Recent Comments

Recent Posts

Tags

actuators aircraft atc blog chaos chaos_theory charts control controllers controls crisis economy finance flight fractals git gnc gs guidance linux mandelbrot marketing navigation ns ofc on pilot rails ruby sas scs sensors statistics systems techcrunch thinkosphere tutorial typo ubuntu wifi

Categories

Archives

Syndicate


Sponsor