I cloned a git repository, mainrepo
, which has a submodule submodule1
. When I try to get the latest update from submodule1
:
$ cd mainrepo
$ git submodule add git@bitbucket.org:myaccount/submodule1.git
$ git submodule update --remote submodule1
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
$ git submodule update --remote
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--] [<path>...]
I am sure I once tried updating a submodules
this way, the docs says to do so too, yet I do not understand why it does not work.
But if I do a fetch and merge directly in the submodule
, it gets updated to the latest repository commit as I want it:
$ cd submodule1
$ git fetch && git merge master
Why doesn't the submodule update --remote submodule1
command work?
Maybe that might help:
$ vim mainrepo/.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@bitbucket.org:myaccount/mainrepo.git
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "local/src/utils"]
url = git@bitbucket.org:myaccount/submodule1.git
$ vim .gitmodules
[submodule "submodule1"]
path = submodule1
url = git@bitbucket.org:myaccount/submodule1.git
I would recommend reading this crash course on Submodules from git: https://git-scm.com/book/en/v2/Git-Tools-Submodules
My guess is that, since the repository you cloned already has a submodule (check for .gitmodules
in the repo's root!) you shouldn't have to git submodule add
it again.
Cloning the repository and then running git submodule update --recursive
should suffice!
Alternatively, git clone --recurse-submodules
does this automatically for you.