Git Submodules – Updating and Commiting changes

I’m reading Phil’s blog post about GIT submodules, which will be really helpful to me.
http://philsturgeon.co.uk/blog/2011/09/managing-codeigniter-packages-with-git-submodules

I’m wondering about one step in the process of updating a submodule: When you make changes to a submodule and go to check status, it says you’re not in a working tree (“you have no head”?). You’re then supposed to “git checkout master” – ??? – but won’t that undo all the changes you made and return your submodule to a previous state?


So with submodules my understanding is you do the following:

1.) Clone submodule

2.) Init and Update submodule ** you only do this once?

3.) Make changes

4.) Checkout “master” on submodule ** this won’t jack you up?

5.) Commit submodule

6.) Push submodule ** can you commit primary project w/out pushing submodule?

7.) Commit primary project

Just trying to clear things up in my head.


EDIT: I guess there is a difference between cloning a submodule into a project versus pulling an entire superproject. Looks like the “git submodule init && update” is only necessary when pulling entire projects.

  • GIT Change Submodule URL in Post-update script
  • Embedded git repository that tracks our changes?
  • GIT: (Kohana) Project setup
  • Creating multiple remote branches with git submodules
  • different push/pull urls for git submodule
  • Modify snippet of snipmate without changing submodule
  • How to push commits from changes made to a submodule into main git repo?
  • git submodule add only pick latest Commit
  • One Solution collect form web for “Git Submodules – Updating and Commiting changes”

    My starting workflow

    1. Clone a primary project
    2. Init and Update submodule
    3. Go inside interesting submodule and do git checkout -b feature_branch
    4. Do changes
    5. Commit them
    6. Push them
    7. Go up to the primary project
    8. git add && git commit && git push

    Beware! You can push the primary project to some publicly available repository without step 6 but you really should not. Because it became unusable for outsiders.

    My basic workflow (suppose that we already implemented several features)

    1. Go to primary repository and checkout desired branch|tag|commit
    2. Update submodules (this checkouts desired versions of all submodules
    3. Go inside interesting submodule and do git checkout -b feature_branch
    4. Do changes
    5. Commit them
    6. Push them
    7. Go up to the primary project
    8. git add && git commit && git push
    Git Baby is a git and github fan, let's start git clone.