I want to pull/update the submodules at the right branch. Doing git submodule update
pulls/updates the submodules but it changes to the wrong branch even when the branch I want to ALWAYS use is specified in the .gitsubmodule file.
Only when I do --remote
does it work (but then I don't know what other unintended consequences it might have in the rest of my submodules).
I want to updat my modules exactly as specified in my .modules files. How do I do this?
e.g.
[submodule "pytorch-meta-dataset"]
path = pytorch-meta-dataset
url = [email protected]:brando90/pytorch-meta-dataset.git
branch = hdb
[submodule "meta-dataset"]
path = meta-dataset
url = [email protected]:brando90/meta-dataset.git
Is what I should be running:
git submodule update
git submodule update --remote
git submodule init
git submodule status
I did read the --remote:
--remote
This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s
remote-tracking branch. The remote used is branch’s remote (branch.<name>.remote), defaulting to origin. The remote branch used defaults to the remote HEAD, but the branch
name may be overridden by setting the submodule.<name>.branch option in either .gitmodules or .git/config (with .git/config taking precedence).
This works for any of the supported update procedures (--checkout, --rebase, etc.). The only change is the source of the target SHA-1. For example, submodule update
--remote --merge will merge upstream submodule changes into the submodules, while submodule update --merge will merge superproject gitlink changes into the submodules.
In order to ensure a current tracking branch state, update --remote fetches the submodule’s remote repository before calculating the SHA-1. If you don’t want to fetch, you
should use submodule update --remote --no-fetch.
Use this option to integrate changes from the upstream subproject with your submodule’s current HEAD. Alternatively, you can run git pull from the submodule, which is
equivalent except for the remote branch name: update --remote uses the default upstream repository and submodule.<name>.branch, while git pull uses the submodule’s
branch.<name>.merge. Prefer submodule.<name>.branch if you want to distribute the default upstream branch with the superproject and branch.<name>.merge if you want a more
native feel while working in the submodule itself.
My install script ends up looking retarded:
# -- gitsubmodules
# - set up pytorch-meta-dataset git submodule
cd ~/diversity-for-predictive-success-of-meta-learning/
# adds the submodule to the .gitmodules file & pull the project
git submodule add -f -b hdb --name pytorch-meta-dataset [email protected]:brando90/pytorch-meta-dataset.git pytorch-meta-dataset/
git submodule update --init --recursive --remote pytorch-meta-dataset
# - set up meta-dataset git submodule
# adds the submodule to the .gitmodules file & pull the project
git submodule add -f -b master --name meta-dataset [email protected]:brando90/meta-dataset.git meta-dataset/
# - git submodule update to fetch all the data from that project
git submodule update --init --recursive --remote meta-dataset
# - initialize your local configuration file
git submodule init
# - check the submodules
git submodule status
why do I need to specify the same thing so many times? What is the point of the .gitmodules file then at all? It can't even update things properly without screwing up the rest of the subdmodules
Look at the branchdes:
(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ git submodule status
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
6e60161962ae3fa309335da7aa1c675c75ecca54 pytorch-meta-dataset (heads/hdb)
they don't even match my .gitmodules
[submodule "pytorch-meta-dataset"]
path = pytorch-meta-dataset
url = [email protected]:brando90/pytorch-meta-dataset.git
branch = hdb
[submodule "meta-dataset"]
path = meta-dataset
url = [email protected]:brando90/meta-dataset.git
branch = master
related:
- How can I specify a branch/tag when adding a Git submodule?
- How do I pull newly specified submodules that I just added in my .gitmodules file?
- cross: https://www.reddit.com/r/git/comments/101urnl/why_do_i_need_to_add_the_remote_to_gits_submodule/
- quora cross: https://www.quora.com/unanswered/Why-do-I-need-to-add-the-remote-to-gits-submodule-when-I-specify-the-branch-in-the-gitmodule-file
Extra: Why does git submodule status not match the output of git branch of my submodule?
Why does it still not work even if I specified the --remote?
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule add -f -b hdb --name meta-dataset [email protected]:brando90/meta-dataset.git meta-dataset/
Cloning into '/Users/brandomiranda/ultimate-utils/tutorials_for_myself/my_git/meta-dataset'...
remote: Enumerating objects: 2947, done.
remote: Counting objects: 100% (740/740), done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 2947 (delta 689), reused 675 (delta 675), pack-reused 2207
Receiving objects: 100% (2947/2947), 3.17 MiB | 4.51 MiB/s, done.
Resolving deltas: 100% (2248/2248), done.
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule init
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule update --init
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule update --init --remote
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule status
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule update --init --recursive --remote meta-dataset
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ git submodule status
ca81edbf5093ec5ea1a1f5a4b31ec4078825f44b meta-dataset (arxiv_v1-200-gca81edb)
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git ❯ cd meta-dataset
(meta_learning) brandomiranda~/ultimate-utils/tutorials_for_myself/my_git/meta-dataset ❯ git branch
* hdb
git version 2.37.0 (Apple Git-136)
it seems. – Multipurpose