After I git submodule update
it always checks out the same commit. for example 34561
.
I do git checkout master
for submodule a
You need to go into the submodule folder and execute:
git fetch --all --prune
git pull origin master
And now you will have the latest commit in the submodole.
Once you run the fetch its updatigng your .git
folder under the submodule with the latest commits. It will make sure that you have the recent changes.
I mean why it decided to point to that commit and not another?
Because a submodule always records a fixed SHA1 commit in the parent repo as a gitlink (a special entry in the index).
That is why a submodule is always restored as a detached HEAD branch
You can configure a submodule to follow a branch
cd /path/to/your/parent/repo
git config -f .gitmodules submodule.<path>.branch <branch>
The submodule would still be restored to a fixed commit, but can then be updated with:
git submodule update --remote
Make sure to add and commit the new gitlink in the parent repo (since updating a submodule to the latest of a branch would change its SHA1, recorded in the parent repo as a gitlink).
If you don't, you will find back your submodule to its previous state at then next git submodule update --init
.
See more at "Git submodules: Specify a branch/tag".
The 'main' project contains a reference to the SHA-1 of the checked out version each submodule. This is part of the commit in the main project.
If you change the head of a submodule manually in the submodule, you need to tell the main project that from now on it should use this SHA-1 for the submodule.
git commit -a
will do this, as the main project will see the submodules head was updated.
This may be surprising, but it is actually a nice feature. With checking in the head in the main project, you basically tell your colleagues that it is now ok to use the newer version of the submodule. This allows people to work together without too much risk of pulling the rug under others feet.
(That being said, there are many warts in a workflow with submodules, and you probably should agree an approach and the cement it with some team scripts to avoid the pitfalls).
You can execute:
git submodule foreach git pull origin master
This will update all your submodules.