git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* feature request - can git submodule update pull/update the repos based on the .gitmodule file without additional flags?
@ 2023-01-03 19:36 Brando Miranda
  0 siblings, 0 replies; only message in thread
From: Brando Miranda @ 2023-01-03 19:36 UTC (permalink / raw)
  To: git; +Cc: Brando Miranda

I find i have a git submodule file .gitmodule and when I go git submodule update, it ignores the stuff I wrote/have in my .gitmodule e.g. I have the exact branch I want to use. Why isn't the default behaviour of gitsubmodule to obey my .gitmodule file? It is very unintuitive. Then what is the .gitmodule file for?

More details:
- https://stackoverflow.com/questions/74988223/why-do-i-need-to-add-the-remote-to-gits-submodule-when-i-specify-the-branch 

copy pasting contents of url:

Why do I need to add the `--remote` to git's submodule when I specify the branch in the .gitmodule file?

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 = git@github.com:brando90/pytorch-meta-dataset.git
	branch = hdb
[submodule "meta-dataset"]
	path = meta-dataset
	url = git@github.com: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 git@github.com: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 git@github.com: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 = git@github.com:brando90/pytorch-meta-dataset.git
	branch = hdb
[submodule "meta-dataset"]
	path = meta-dataset
	url = git@github.com:brando90/meta-dataset.git
	branch = master
```

----


related:
- https://stackoverflow.com/questions/1777854/how-can-i-specify-a-branch-tag-when-adding-a-git-submodule
- https://stackoverflow.com/questions/74988266/how-do-i-pull-newly-specified-submodules-that-i-just-added-in-my-gitmodules-fil?noredirect=1&lq=1
- 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




-----
Brando Miranda
brandojazz@gmail.com




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-03 19:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 19:36 feature request - can git submodule update pull/update the repos based on the .gitmodule file without additional flags? Brando Miranda

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).