0

Hello I have a problem when creating a sumodule. The problem is as follows: Lets say there is a repos called submod. And I have a empty project called proj. Now I clone the proj and make a folder called lib. After creating the folder I create the submodule:

cd lib
git init
git submodule add "gitlink for submod"

After that it created a submodule in the folder lib. Now the problem is that there is a extra folder i do not need.

  1. root
  2. lib
  3. submod
  4. submod files

I want it to be like this:

  1. root
  2. lib
  3. submod files

I could not find a solution for this seemingly easy problem.

  • 1
    you are doing that wrong. You are creating regular repository `git init` and in same place you are trying add sumbomdule `git submodule add` but you are passing wrong parameter: "gitlink for submod". Please read [documentation first](https://git-scm.com/docs/git-submodule). If you are new to git it would be best not to use submodules (they are much harder to understand). – Marek R Sep 01 '22 at 07:28
  • Thanks for your answer. Yes I am kind of new t Git. But it is neccessary for me to use submodules in this particular case. I will read the documentation and try again. – Christoph.Renzl Sep 01 '22 at 07:37
  • I found a solution! So I now used Tortoise Git to add a new submodule. What is important is that the you do not make a folder in which you want the submodule to be in. In tortoise Git you can put your repos link for the submodule and after that decide the path. In the path you choose the parent folder of your submodule folder. And instead of the auto-apendix you can type in your folder name. – Christoph.Renzl Sep 01 '22 at 08:14

1 Answers1

0

A Git submodule always occupies a folder (directory) because it's actually a second, additional Git repository and as such it needs its own hidden .git. (This was once an additional .git folder; now it's a .git file but everything else is still arranged as if it were a hidden .git folder within the submodule folder.)

In command-line Git, then, you'd normally do this (I'll assume here that you're using GitHub and prefer to have GitHub make the first commit within each repository, then clone them, rather than the more complicated "make the repository locally, make a first commit, make an empty GitHub repository making sure not to make a first commit there, do some other more-complicated stuff, etc." sequence):

  1. Make the new repository on GitHub for the project itself.
  2. Make the new repository on GitHub for the submodule.
  3. git clone ssh://git@github.com/me/proj.git to make a clone named proj for the project. (This assumes you're using ssh; adjust the URL for https if you are using HTTPS.)
  4. cd proj to enter the cloned project.
  5. git submodule add ssh://git@github.com/me/lib.git lib to tell Git to make a clone named lib from ssh://git@github.com/me/lib.git whenever it goes to get the submodule. Your own Git will now make that clone as well, and you now have everything set up.

Note that git submodule add won't bother making a clone if the clone already exists. In that case you probably want to run git submodule absorbgitdirs. See How to make an existing directory within a git repository a git submodule as well.

torek
  • 448,244
  • 59
  • 642
  • 775