vmonteco vmonteco - 3 months ago 18
Git Question

Git submodule add: "a git directory is found locally" issue

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

In my Travail repository, I already added a project of mine as a submodule at

tools/libft
:
I'm able to develop this submodule, to push and to pull it.

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

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

A git directory for 'projets/fdf' is found locally with 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 cloning again 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 are unsure what this means choose another name with the '--name' option.


There is actually no subdirectory in
projets/


I read on an other thread that I should use git submodule sync or edit the .gitmodules file in which the URL to my submodule's origin repository could have changed.

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

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


As a French student I could have missed something in the english documentation I have, but I searched and I really don't understand why I get this issue.

I would be glad if I would get a solution but just an explanation would be helpful too.

Answer

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, then commit the changes. After that you'll be able to add this folder as a submodule.