Developing Rails Gems with Git

Take a gem that provides shared functionality to a number of under-development projects. Gem development takes place alongside each project, and while back-compatibility is tested prior to each commit, features included in subsequent versions of the gem may prove useful to projects other than the one that added them. To complicate matters slightly, the constant state of development means the gem itself is under version control itself. Develop as needed, let git handle the magic. No surprise there.

Once the gem is set up, there are a couple of ways to get it into rails. An unregistered gem that isn’t under active development may be added to the bundle directly via a remote repository. For instance, it’s fairly common to include unregistered gems directly from github:

# in Gemfile
gem 'sable', :git => ''

If the gem is being actively developed alongside the application, however, it may make better sense to add it as a git submodule and reference it directly:

$ git submodule add lib/sable

# in Gemfile
gem 'sable', :path => 'lib/sable'

Now, the gem may be modified directly from the lib/my_gem directory. Once new features meet the obligatory compatibility test, it may be pushed back to github for use by other projects:

$ cd lib/sable
$ git commit -a -m "added a new feature"
$ git push origin