How do I "commit" changes in a git submodule?

Dylan Beattie picture Dylan Beattie · Apr 4, 2011 · Viewed 203.3k times · Source

I have, in my naivety, set up a git submodule and treated it like a Subversion external - i.e. it's now full of changes that I've just realized haven't been committed or pushed anywhere.

Is there some easy way to commit/push the submodule changes back to the upstream repo? And what's the recommended technique in Git for doing simultaneous development on separate (but linked) repositories in this way?

Answer

timdev picture timdev · Apr 4, 2011

A submodule is its own repo/work-area, with its own .git directory.

So, first commit/push your submodule's changes:

$ cd path/to/submodule
$ git add <stuff>
$ git commit -m "comment"
$ git push

Then, update your main project to track the updated version of the submodule:

$ cd /main/project
$ git add path/to/submodule
$ git commit -m "updated my submodule"
$ git push