0

If a parent repository has many submodules. Does the parent repository store the current commit of the submodule?

When I check out the parent repository on a fresh install of the parent repository it doesn't appear to be deploying the most up to date version of the submodule.

The clone command the box boots up with is.

git clone --recursive repo_url folder 

3 Answers 3

1

The parent repository stores the commit hash of each submodule, not the code of the submodule itself. When you clone the parent recursively it will clone the submodules up to that commit. This is actually a good thing because you wouldn't want git pulling a newer version of a submodule as your parent may not be compatible with it.

To update a submodule you must do it explicitly:

cd submoduledir/ git pull origin master cd .. git status 

Then commit the updated submodule:

git add submoduledir git commit -m "Update submodule" 

If you are updating your local copy from a master that has updated submodules you do this:

git pull origin master git submodule update --recursive 
Sign up to request clarification or add additional context in comments.

Comments

0

It doesn't store it, instead just knows which commit had the submodules where and where it current is at. Check this.

And to get the latest of the submodules use:

git submodule foreach --recursive 'echo `git checkout master`' git submodule foreach --recursive 'echo `git pull`' 

Assuming you want all the submodules to be at the master branch.

To preserve the state commit it.

3 Comments

Clever, although I would do 'echo git checkout master && git pull' as running them separately would ignore any errors from the first. Only cavet is assuming that every submodule uses the master branch.
@Luke I was planing to join the two but thought of keeping it simple. how would it ignore any error in the first? Yes I made that assumption @ master branch
The && causes git pull to be skipped if git checkout master returns with a non-zero exit code.
0

Note, complementary to the other answers: when you already have a clone, you can change to another tag, branch or hash (REF below) while keeping the submodules consistent by using

git checkout --recurse-submodules REF 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.