Update a submodule to the latest commit


I have a project A which is a library and it is used in a project B.

Both projects A and B have a separate repository on github BUT inside B we have a submodule of A.

I edited some classes on the library, which is in the repo A, I pushed on the remote repo, so the library (repo A) is updated.

These updates do not reflect on the "reference" (the submodule) the submodule refers to a previous commit.... what should I do in order to update the submodule on git?


Enter the submodule directory:

cd projB/projA

Pull the repo from you project A (will not update the git status of your parent, project B):

git pull origin master

Go back to the root directory & check update:

cd ..
git status

If the submodule updated before, it will show something like below:

# Not currently on any branch.
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#       modified:   projB/projA (new commits)

Then, commit the update:

git add projB/projA
git commit -m "projA submodule updated"


As @paul pointed out, since git 1.8, we can use

git submodule update --remote --merge

to update the submodule to the latest remote commit. It'll be convenient in most cases.

How do I finish the merge after resolving my merge conflicts?

Is there a git-merge --dry-run option?