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

Bug in Submodule add

From
JJJonathan Johnson <me@jondavidjohn.com>
Date
Sep 26, 2012, 04:18 UTC
Message-ID
<BC634E06939C44239106E7A8DD229130@gmail.com>
I believe I have found an issue with the way `submodule add` detects a submodule that already exists in the repository. 
To reproduce
1) add a git submodule in a specific location (we'll say it's at `./submodule/location`)
2) go through the normal steps of removing a submodule, as listed here - https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial
3) Now the submodule is completely removed and there is no reference to it in .gitmodules or .git/config
4) Re-add a different repository at the same location (`./submodule/location`)
Expected - The new submodule repository will be set up at ./submodule/location and have the new repository as its origin
What Actually Happens - The new submodule uses the existing `$gitdir` (old repository) as the actual backing repository to the submodule, but the new repository is reflected in .gitmodules and .git/config.
So to recap, the result is that `git remote show origin`  in the submodule shows a different origin than is in .gitmodules and .git/config
One simple step to remedy this would be to add the deletion of the backing repository from the .git/modules directory, but again, I think an actual command to take care of all of these steps is in order anyways.  Not sure you want to encourage people poking around in the .git directory.
If this is already resolved in the newest versions, please disregard
Thanks!
Jonathan Johnson
http://jondavidjohn.com | me@jondavidjohn.com
Next: Jens Lehmann
Message 1 of 9 in “Bug in Submodule add”
  1. Jonathan JohnsonSep 26, 2012
  2. Jens LehmannSep 26, 2012
  3. 0/2 Let "git submodule add" fail when .git/modules/<name> already existsJens Lehmann, Sep 29, 2012
  4. 1/2 Teach "git submodule add" the --name optionJens Lehmann, Sep 29, 2012
  5. 2/2 submodule add: Fail when .git/modules/<name> already existsJens Lehmann, Sep 29, 2012
  6. Junio C HamanoSep 30, 2012
  7. Jens LehmannSep 30, 2012
  8. 2/2 submodule add: Fail when .git/modules/<name> already exists unless forcedJens Lehmann, Sep 30, 2012
  9. Junio C HamanoOct 1, 2012

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.