git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git Submodules ref setting

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
May 12, 2022, 22:42 UTC
Message-ID
<88fa7138-cb3f-ab88-525c-198396b0a262@gmail.com>
In-Reply-To
<F20FCD5B-7788-4D4C-8402-2C4CF447B2F5@gmail.com>
Hi, 
Le 2022-05-12 à 16:01, Вадим Цветков a écrit :
Show 5 quoted lines
> Hello,
> 
> I've started a small project which involves several git repositories, which depends on each other.
> For dealing with these repos I wanted to use git submodules as a simple package manager.
> However, it seems impossible to lock a submodule to particular ref, only to a branch.

Submodules are recorded in the superproject *at a specific commit*. That's the data model. There is no other options.

There is a 'branch' setting that you can put in '.gitmodules'. This *only* affects the command 'git submodule update --remote', nothing else.

If you mean that you would like to have a non-branch ref recorded in '.gitmodules' i.e. something like refs/other-refs/example instead of 'some-branch' that corresponds to 'refs/heads/some-branch', then no this is not possible either.

> I would like to ask if this is deliberate design choice?

Yes, it was a deliberate design choice to have a deterministic state of a repository using submodules upon 'git clone'. Recording a submodule at a specific branch instead of at a specific commit would make this design choice impossible to achieve.

> And if it's not, may I contribute this feature?
> 
It depends on what you mean by 'lock submodule to a specific ref'.

I encourage you to read the "Git Submodules" chapter of the Pro Git book [1] for an in-depth overview of how submodules work. And after that, for reference the Git documentation:

- git-submodule(1): https://git-scm.com/docs/git-submodule
- gitsubmodules(7): https://git-scm.com/docs/gitsubmodules
- gitmodules(5): https://git-scm.com/docs/gitmodules
I hope that helps,
Philippe.
[1] https://git-scm.com/book/en/v2/Git-Tools-Submodules
Previous: Philip OakleyNext: Philip Oakley
Message 3 of 5 in “Git Submodules ref setting”
  1. Вадим ЦветковMay 12, 2022
  2. Philip OakleyMay 12, 2022
  3. Philippe BlainMay 12, 2022
  4. Philip OakleyMay 13, 2022
  5. Junio C HamanoMay 13, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.