Git

How to commit changes to Git submodules.

A Git submodule is a nested repository. You might be interested in creating such repository if you have a multiple repos with a shared folder of code.
You could copy and paste that code between repos when there is a change, but a shared repo set as a submodule could help keep it in sync.

I’ve recently become less impressed by the usages of submodules, and would suggest flattening your repos where possible, or using some type of package management tool like npm or nuget instead for a similar effect. But if you want to use submodules, below is a basic explanation of how to make a change in one.

Imagine 3 repos: Main, Other, and Sub (i.e. the shared submodule). Assume we are using a GitFlow-like workflow in Main and Other: http://nvie.com/posts/a-successful-git-branching-model/. Imagine Sub has only one branch named master.

First, make sure you don’t override other changes in Sub.

  1. Have the latest from develop in your current local branch in the Main and Other repos.
  2. Verify in Sub, for both Main and Other repos, that the latest commits on that master branch are being already pointed to.
    1. Checkout and Pull the master branch in each copy of Sub.
    2. Check your uncommitted changes in Main and Other.
    3. You can also check the commits in the main repos to see which commit in Sub each is pointed to.
  3. If you have uncommitted changes in either top-level repo, changes in Sub (either on someoneโ€™s branch, or in one repo but not the other) have not been updated in develop.
    1. Speak to the developer if you have any questions about the changes.
    2. Commit and push the Sub changes in each top-level repo if reasonable.

Then, make your changes to the submodule.

  1. Make your changes into the relevant subdirectory of Sub nested in the Main repo.
  2. Commit and push Main’s Sub master changes.
  3. Commit and push the Main repo reference change to the latest commit in Sub.
  4. Pull the Other’s Sub master changes.
  5. Commit and push the Other repo reference change to the latest commit in Sub.

I hope that helps, and as always leave me a comment below if you have any questions.