Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 737
fat Avatar asked Nov 19 '11 02:11

fat


People also ask

How do I update a specific submodule?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

What does git submodule update -- Remote do?

git submodule update --remote will only update the branch registered in the . gitmodule , and by default, you will end up with a detached HEAD, unless --rebase or --merge is specified or the key submodule.

Can I edit git submodule?

If you want to make a change within a submodule, you should first check out a branch, make your changes, publish the change within the submodule, and then update the superproject to reference the new commit.

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.


2 Answers

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" 

UPDATE

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.

like image 54
Kjuly Avatar answered Sep 27 '22 21:09

Kjuly


Since git 1.8 you can do

git submodule update --remote --merge 

This will update the submodule to the latest remote commit. You will then need to add and commit the change so the gitlink in the parent repository is updated:

First, git add it

git add project/submodule_proj_name 

then git commit it

git commit -m 'gitlink to submodule_proj_name was updated' 

the git push it

git push 

And then push the changes as without this, the SHA-1 identity the pointing to the submodule won't be updated and so the change won't be visible to anyone else.

like image 34
Paul Hatcher Avatar answered Sep 27 '22 21:09

Paul Hatcher