Git subodule add: "Git directory found locally"

I'm really trying to learn how to use git, including the git subodule subcommands. I have already set up a server on which I can host, push and pull git repositories using ssh. I created the main git repository "Travail" on this server, in which I would like to put all my projects as submodules.

In my Travail repository, I already added my project as a submodule in tools/libft : I can develop this submodule, click and pull it out.

But when I try to add another submodule (named fdf, from fdf.git on my server), I get the following problem:

 git submodule add ssh://XXX.XXX.XXX.XXX:XXXXX/opt/git/fdf.git projets/fdf 

The git directory for 'projets / fdf' is locally with the remote (s): origin ssh: // git @ XXX.XXX.XXX.XXX: XXXXX / opt / git / fdf.git If you want to reuse this local git directory instead of re-cloning from SSH: //XXX.XXX.XXX.XXX: XXXXX / opt / git / fdf.git use the '--force' option. If the local git directory is not the correct repo or you do not know what it means, select a different name with the "--name" parameter.

Actually there is no subdirectory in projets/

I read in another thread that I should use the git submodule synchronization or edit the .gitmodules file in which the URL in the source submodule repository could be changed.

But my .gitmodules file contains only information about my first submodule (tools / libft), and not about / fdf files:

 [submodule "tools/libft"] path = tools/libft url = ssh://git@XXX.XXX.XXX.XXX:XXXXX/opt/git/libft.git 

As a French student, I might have missed something in the English documentation, but I was looking, and I really don't understand why I am getting this problem.

I would be glad if I got a solution, but only an explanation would be useful.

+108
git git-submodules
Jan 05 '14 at 2:32
source share
6 answers

I came to this SO post trying to add a submodule with the same path as the submodule that I recently removed.

This is what ultimately worked for me ( this article helped a lot ):

If you have not git rm --cached path_to_submodule (without a trailing slash), as well as rm -rf path_to_submodule , do it!

Then:

  • Remove the corresponding lines from the .gitmodules file. For example, delete them:

    [submodule "path_to_submodule"] path = path_to_submodule url = https://github.com/path_to_submodule

  • Remove the appropriate section from .git / config. For example, delete them:

    [submodule "path_to_submodule"] url = https://github.com/path_to_submodule

  • rm -rf .git/modules/path_to_submodule

Then you can finally:

git submodule add https://github.com/path_to_submodule

+234
Mar 03 '16 at 16:48
source share

I tried the jbmilgrom solution, in particular, I tried git rm --cache , and this did not work for me, since the directory / submodule was not there. What worked for me:

  • rm -rf .git/modules/blah
  • git submodule add git://path.to.new

I did this by trying --force in the git submodule and rm commands of all other directories, clicking on the wizard, etc., the directory did not exist and there was no reason for the cache. It turns out in .git/modules where this error lay.

+31
Jul 17 '16 at 11:06
source share

You may have deleted your 'projets/fdf' from disk, but your Git repository still has it. Use git rm -rf projets/fdf to remove it from Git and then commit the changes. After that, you can add this folder as a submodule.

+15
Jan 05
source share

If you have already deleted the submodule directory, like me, follow the instructions from jbmilgrom. The key is rm -rf .git/modules/path_to_submodule , but go ahead and first back up the entire directory of the parent repo .

If you had only one submodule, just delete .gitmodules

+11
Feb 07 '17 at 21:11
source share

I tried these answers and they did not help me. The only thing that worked for me was deleting my parent repo and removing it again. Hope this helps someone

0
Nov 19 '18 at 23:30
source share

These two teams work for me.

 rm path/to/submodule -rf rm .git/modules/path/to/module -rf 
0
Jan 28 '19 at 3:05
source share



All Articles