Harry Seldon's blog

Fractals, Chaos, and Control Systems on Rails


Git and Rails: A detailed tutorial including plugins, submodules, development and production

Posted by Harry Seldon on January 14, 2009

I had started talking about setting up a development and production environment with git for Typo in this post. Because of this new version of Typo, I have finally had a very good reason to change the set up of this blog and to migrate to git. Installing Typo from its git repository, I have had the opportunity to use the git submodules. That is why in this post I will use the Typo blog engine to make a case study for the use of git with:

  • Several repos for development, production and deployment
  • Several repos for open source development
  • Use of submodules for plugin management and development

Indeed, my own aims for this new setup are to:

  • Have a test environment and a production environment for this blog
  • Be able to update the blog engine from its main repository
  • Be able to contribute to this open source blog engine
  • Manage properly rails plugins
  • Be able to contribute to these plugins

The final setup is as following, represented on the figure below:

  • I have a repository where I develop and test Typo. This repo is first created by cloning Typo’s repo. From my point of view this is the main repo. Indeed I can pull from Typo’s repo or push to it. in the same way I can push to the production repo, to deploy. Deployment can be managed easily by Capistrano in this configuration. Notice that several branches can be contained in the repo (public branch pushed to the main repo, private production branch, etc.)
  • Production repo. The actual production code is a checkout from this repo.
  • My public dev repo. It contains the changes I can propose to Typo’s dev team through a ‘pull request’.
  • Main repo. Currently it is Fred’s repo but thanks to git architecture it could be as well the public repo of who you want.
  • Fred’s private repo. He may have several dev repos, with plenty of branches, on several computers .
  • Cyril’s public repo.
  • Cyril’s private repo

git image
For each repo, the plugins are put in subrepo and managed through git submodules. That is, each plugin has its own repo and is not included in Typo’s repo. However, the beauty of the submodules is that you can really easily develop and update your plugins.

Now let’s go for a detailed tutorial to set this up.
This setup is for people willing to have a full development environment. However, if you just want to install Typo, you simply need to skip the first step, the creation of the public repo. And in this case you can consider that your public user name is ‘fdv’ but you will not be able to push to the repos.

Create your public repo
Fork Typo on github using your account. As you are doing that, also fork the plugins that interest you, for instance Recent comments, Recent posts and Related posts.

Create your dev repo
Then, clone the Typo repo from your public repo. Type this command in the local directory of your choice. Replace the user name harryseldon by your name.

git clone git://github.com/harryseldon/typo.git

To be able to update your dev repo with the latest changes, add the address of the main repo:

git remote add main_typo git://github.com/fdv/typo.git

Then to update your copy, you simply need to pull the changes:

git pull main_typo master

NB. The repo you clone from will be called ‘origin’ in your local copy. If you prefer you can initially clone from the main repo and then add the address of your github repo.

In order to run, like every Rails app, Typo requires some plugins. They are managed through the git submodules. So you just need to run:
[EDIT 3/8/2009] Typo plugins are now managed using gems, check this post.

git submodule update --init

With this command the plugins will be pulled from the addresses written in the .gitmodules file which looks like this:

[submodule "vendor/rails"]
  path = vendor/rails
  url = git://github.com/rails/rails
[submodule "vendor/actionwebservice"]
  path = vendor/actionwebservice
  url = git://github.com/datanoise/actionwebservice.git
[submodule "vendor/plugins/rspec"]
  path = vendor/plugins/rspec
  url = git://github.com/dchelimsky/rspec.git
[submodule "vendor/plugins/rspec-rails"]
  path = vendor/plugins/rspec-rails
  url = git://github.com/dchelimsky/rspec-rails.git
[submodule "vendor/plugins/will_paginate"]
  path = vendor/plugins/will_paginate
  url = git://github.com/mislav/will_paginate.git

If you have your dev version of one of these plugins, do not hesitate to change the address to point to your public repo.

Then you may want to install your preferred Typo plugins. The ones you have just forked on github.

git submodule add git://github.com/harryseldon/typo_related_posts.git vendor/plugins/typo_related_posts
git submodule add git://github.com/harryseldon/recentposts_sidebar.git vendor/plugins/recentposts_sidebar
git submodule add git://github.com/harryseldon/recent_comments_sidebar.git vendor/plugins/recent_comments_sidebar

and again

git submodule update --init

To use Typo in your dev environment, you finally need to configure your database. Use your usual settings and run the migrations. Typo will work like any other Rails app.

Like any other git repo, feel free to create as many branches as you like. For instance you can create a production branch:

git branch typo_production

You would typically set the environment to production in environment.rb.

Create your production repo
Assuming an ssh connection, you create the repo on your host in a ~/git/Typo directory.

git init

You add the address of this repo to your dev repo:

git remote add production_repo ssh://user@ssh.domain.com/home/user/www/git/typo/.git

Now you can push your code to production. Let us say you created a special production branch,

git push production_repo typo_production

This step could be done using Capistrano and pushing the development branch. Capistrano would be typically in charge of making the changes in environment.rb.

Commit changes
Assuming you made some changes in your dev repo. You commit them:

git commit -a -m "my changes"

Then you can push them to your public repo:

git push 

Accordingly with the previous NB, this is equivalent to:

git push origin master

Then from your github account, you can send a “pull request” to Typo maintainers if you would like to see your changes included in the official Typo code.

As far as the plugins are concerned, the process is similar. You cd to your plugin folder which is under a git version control and you can push, just like for the Typo repo.

Following this tutorial, you have installed a typical environment for a Rails application under git version control.

Feel free to leave comments about the git environment or the Typo installation.

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



Use the following link to trackback from your own site:

  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 ...
  2. News from Typo edge From Harry Seldon's blog
    I have updated this blog engine in order to install the recently added Feedburner support. My recent post about [Rails heroes RSS feeds](http://harryseldon.thinkosphere.com/2009/02/03/read-your-rails-heroes) clearly showed me that feedburner was a...


Leave a response

  1. Harry Seldon on January 23, 2009 at 11:16 pm

    Nota, if you install Typo, beware of your public/robots.txt. Replace it by:
    User-agent: * Disallow: /admin (Or by whatever you want)

    The current version will prevent your blog from being indexed by GoogleBot.
    [EDIT] Issue is corrected.

  2. Evgeny on January 25, 2009 at 04:51 pm

    You can also use submodules for vendor/gems.

    Though it will be hard with the current way that Rails 2.2 is handling frozen gems.

    I have a patch that removed the version number from the gem folder, and is using the original gemspec.

    So instead of Rails 2.2 way of using: vendor/gems/haml-2.0.7/.specification

    After the patch what is used is: vendor/gems/haml/haml.gemspec

    And this is also the file that you get when cloning any proper gem from github.

    The patch is available here: http://gist.github.com/41380

  3. Tobias Weisserth on February 07, 2009 at 08:33 pm

    I like your blog.

    But instead of “git remote main_typo git://github.com/fdv/typo.git” shouldn’t it rather be “git remote add main_typo git://github.com/fdv/typo.git” or “git-remote add main_typo git://github.com/fdv/typo.git”?

  4. Tobias Weisserth on February 07, 2009 at 09:37 pm
  5. Harry Seldon on February 09, 2009 at 02:24 pm

    @ Tobias, yes you are right on both points, thanks. It is “git remote add” and there were changes in the way Typo deals with the Rails plugins. I do not know why though. However, as far as the Typo plugins (recent comments, etc.) are concerned, what is said here still applies.

  6. Tobias Weisserth on February 21, 2009 at 12:28 am

    Hi Harry,

    the submodules have been replaced with using the available gems for things like will_paginate and such. gems reflect stable snapshots so I guess that has been the motive here. However, I still use submodules to pull in plugins and themes.

    thanks again for this inspiring blog post!


  7. My Blogging Net on July 17, 2009 at 06:16 am

    I just want to say thank you for the information that you have been shared. Although some words are not too familiar to me, I am glad that I have read your post.

  8. Mike Zazaian on August 31, 2009 at 07:23 am

    Thanks for the great article. One of the more useful perspectives that I’ve found on Git submodules. Here’s another tutorial that extends on submodules in a slightly more lighthearted manner:


Leave a comment

Markdown enabled



Recent Comments

Recent Posts


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