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/configand.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,.gitmodulesand 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