Skip to content

Step 8: Updating the parent git repository when a submodule is updated

Elias Ranz-Schleifer edited this page Jan 23, 2020 · 1 revision

By default a commit/push to a submodule's git repository won't be reflected on the parent without some manual intervention. Since it's 2 different sources of version control you have to update the parent. Let's go ahead and do that now. First we'll add a README.md file into the foo repo, and then update the submodule.

$ pushd foo
~/git/submodule-poc/foo ~/git/submodule-poc <target directory> <source directory>

$ touch README.md

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	README.md

nothing added to commit but untracked files present (use "git add" to track)

$ git commit -m "Added empty README"
[master 7cd5b60] Added empty README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

$ git push
Warning: Permanently added the RSA host key for IP address '<OMMITED>' to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 274 bytes | 274.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: This repository moved. Please use the new location:
remote:   git@github.com:EliasRanz/submodule-poc-submodule.git
To github.com:EliasRanz/submodules-poc-submodule.git
   6a1fd88..7cd5b60  master -> master

$ popd
~/git/submodule-poc <source directory>

$ git submodule update --remote

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

	modified:   foo (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

$ git commit -am "Updated foo submodule"
[master e98d9ba] Updated foo submodule
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 268 bytes | 268.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:EliasRanz/submodule-poc.git
   3e663c4..e98d9ba  master -> master

Now that we pushed an update to the submodule, if you go back to the UI you should see the commit hash change. That is good and means you're good to go!

Clone this wiki locally