Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 a 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 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 another 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://[email protected]: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 another 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://[email protected]: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.

like image 617
vmonteco Avatar asked Jan 05 '14 02:01

vmonteco


People also ask

How do I add an existing git repository to a submodule?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

How do I change my submodule location?

Git Submodules Moving a submodule If needed, create the parent directory of the new location of the submodule ( mkdir -p new/path/to ). Move all content from the old to the new directory ( mv -vi old/path/to/module new/path/to/submodule ). Make sure Git tracks this directory ( git add new/path/to ).

Why you should not use git submodules?

This is because of some major drawbacks around git submodules, such as being locked to a specific version of the outer repo, the lacking of effective merge management, and the general notion that the Git repository itself doesn't really know it's now a multi-module repository.


1 Answers

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

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

If you haven't already run
git rm --cached path_to_submodule (no trailing slash) as well as
rm -rf path_to_submodule

Then:

  1. Delete the relevant lines from the .gitmodules file. e.g. delete these:
[submodule "path_to_submodule"]         path = path_to_submodule         url = https://github.com/path_to_submodule 
  1. Delete the relevant section from .git/config. e.g. delete these:
[submodule "path_to_submodule"]         url = https://github.com/path_to_submodule 
  1. rm -rf .git/modules/path_to_submodule

Then, you can finally:

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

like image 110
jbmilgrom Avatar answered Sep 20 '22 21:09

jbmilgrom