What does "--remote" actually do in "git submodule update --remote"?
Asked Answered
G

2

8

I just do not understand the help page of Git. So what does happen or what is the difference?

Assume I have a Git project A with a submodule B. Submodule B does have a submodule C. After cloning the repository A points to a specific commit of B. And B points to a specific commit of C.

If I am inside A I go to B by

cd B

Now I type

git submodule update --remote

or

git submodule update

What is the difference? Assuming that the remote server does have changes in A, B and C.

I guess that using "git submodule update --remote" keeps the reference to the specific version of C. Does using it without --remote update to the latest version of C?

Goodtempered answered 24/11, 2017 at 9:36 Comment(0)
B
11

Suppose B is the only submodule of A.

cd A
git ls-tree -r HEAD | grep commit

The output is something like

160000 commit 0814c6ba8f45829f04709c56118868d2483444c2 foo

foo is the submodule folder and 0814c6ba8f45829f04709c56118868d2483444c2 is its revision tracked by A's current commit.

git submodule update does something like

cd B
git checkout 0814c6ba8f45829f04709c56118868d2483444c2

git submodule update --remote is like

cd B
git fetch origin master
git checkout origin/master

By default master and origin/master are used. If the branch is specified by submodule.foo.branch = bar in .gitmodule, thenbar and origin/bar are used.

Belgravia answered 24/11, 2017 at 10:11 Comment(5)
quite a newb in Git, can I assume "git submodule update" should never be used, since we always want the latest version of the sub moduleHurty
@RichardFu It depends. In some cases you may need the latest revision and in others you may not.Belgravia
Could you give a reference? This info is not in git help submodule.Inhumane
@CédricVanRompay See git-scm.com/docs/git-submodule#Documentation/… and git-scm.com/docs/git-submodule#Documentation/…Belgravia
you might want to keep the --remote for release pipelines so you always fetch latest changes of some other repo, but avoid it for feature development as you might want to manually choose which commit to useGuard
G
1

git submodule update --remote

allows you to use the submodule’s remote-tracking branch instead of the specific commit (aka. SHA) recorded in the supermodule.

git submodule update

allows you to use specific commit recorded in the supermodule.

Grivation answered 2/5, 2022 at 6:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.