Git Submodule Gotcha

August 12, 2009

The gotcha comes when I switch branches back and forth between the “master” (no submodules, but with checked in source) and “dev” (where my submodule work is). Here’s what happens:

git checkout master

error: Untracked working tree file ‘vendor/plugins/acts_as_list/lib/active_record/acts/list.rb’ would be overwritten by merge.

Here’s a workaround…
To go back to a branch w/o submodules

rm -rf vendor/plugins
git checkout master
git checkout vendor/plugins

To go back to a branch w/ submodules

git checkout dev
git submodule update --init

Another gotcha, when I tried to merge dev into master I got “fatal: cannot read object… It is a submodule!” A solution is:

git merge -s  resolve

Original Article