Clone submodule in the catalog

I had a problem creating a submodule in my project. If I create a submodule directly in the root of the repository, everything works fine. If the submodule is deeper, the repository is not cloned.

For example, this works as expected:

git submodule add git://someproject.com/.git someproject 

However, when I run the following command, the project is added to .gitmodules and an empty repository is created, but no code is reset (even after git submodule update --init ). The command does not produce any output.

 git submodule add git://someproject.com/.git lib/someproject 
+4
source share
4 answers

It seems that a previous attempt to add a submodule left my repository in a bad state. I was able to correctly clone the submodule after following these steps:

  • Remove the submodule: rm -rf lib/someproject
  • Remove the submodule from the .gitmodules file
  • Remove the submodule from the .git/config file
  • Delete .git/modules/someproject

Then the git add submodule command is executed again. Many thanks to all the defendants who pushed me in the right direction!

+2
source

Try to run

 git submodule init git submodule update 

after adding a submodule.

Update 1

Try the following:

 cd lib/someproject git status 

You should see something like # Not currently on any branch.

If not, then there is no git repo, and you might stumble upon a git error if you see the above message:

 git checkout master git pull 
+3
source

You need to run the following command

 git submodule update --init lib/someproject 

For some reason, git only works in the root directory when starting and updating submodules, and not through the entire working copy.

Also make sure your .gitmodules file contains an entry like this:

 [submodule "someproject"] path = lib/someproject url = git://someproject.com/.git 

And your .git/config file contains:

 [submodule "someproject"] url = git://someproject.com/.git 

Docs:

http://git-scm.com/book/en/Git-Tools-Submodules

+1
source

I just read the submodule section of the O'Reilly book, and the author mentions adding a submodule (manually using git to add the cloned repo in the root of the project in his example), including the trailing slash forcing him to add the folder to the index against creating gitlink. This sounds silly, but maybe try changing directories to lib before you add to make sure that this does not happen to you because of the slash in your path to the submodule.

It can also be a feature of the add submodule, only getting the path and remote url and calling the name of the submodule from the path when writing to configs. Perhaps manually edit the gitmodules and config entries to ensure that the submodule is named without `lib / ', but the path contains it.

0
source

All Articles