The Real Adam Always course correcting

Posted
8 May 2008 @ 5pm

In
Code

Changing git submodule URLs

Pro-tip: if you’re using submodules with Git to manage dependencies (say Rails plugins), you can get yourself into trouble. Like half-a-day of wasted trouble.

The rub comes when you need to make a change to some plugin. Suppose you were using Brain Buster for your captcha and then decided you need to make a change. The git submodule command doesn’t really seem to offer a way to change the URL for the submodule. Let me summarize what I’ve found in trying to do this.

The Wrong Way

  • Fork/create your own version of the submodule in question
  • Change the URL for the submodule in .git/config and .gitmodules
  • Cross your fingers and hope for the best

The Right Way

  • Fork/create your own version of the submodule in question
  • Remove references to the existing submodule in .git/config, .gitmodules and nuke the submodule directory
  • Commit
  • Add the new submodule URL
  • Commit
  • Make changes in your submodule
  • Commit changes in the submodule (not the parent project)
  • Commit the changes in the parent project (otherwise you’ll only get the old version of the submodule in future pulls)
  • Enjoy the hair you didn’t have to rip from your scalp

Learn from my mistakes, people.


3 Comments

Posted by
ch0wda
5 June 2008 @ 3pm

Adam,

Thanks, I have learned from your mistakes. This yak still has all it’s hair.


Posted by
Steve Eley
9 June 2008 @ 1pm

Yes, thank you! We’ve been trying to make submodules work for a repository of code shared between several applications, and the things submodules don’t do that svn:externals did (like auto-updating) have been driving us nuts. We’re starting to wonder if it’s more trouble than it’s worth.


Posted by
Tom
1 July 2008 @ 8am

Out of interest, what’s Wrong with The Wrong Way? As long as you fix up the repository URL in your local clone of the submodule (e.g. edit its .git/config, or just blow it away and git submodule update from scratch) it seems like it should chug along fine without having to completely nuke and re-add the whole submodule. What gives?


Leave a Comment

Ruby for non-Rubyists Info viz with JavaScript

Flickr View All » RubyConf Notes #3RubyConf Notes #2RubyConf Notes #1RubyConf Notes #0Dogs in the morningMy Day, YesterdayGetting aroundMolly loungingasdfjkl;