# Adding existing repo at sub-sub-directory as submodule

1 messages from 2022-09-15 to 2022-09-15. Participants: Jonas Schulze.
Thread: https://gitlist.dev/t/58434

## Jonas Schulze, 2022-09-15 10:49

Subject: Adding existing repo at sub-sub-directory as submodule
Message-ID: <1678038401.2138998.1663238966604.JavaMail.zimbra@mpi-magdeburg.mpg.de>
URL: https://gitlist.dev/e/1678038401.2138998.1663238966604.JavaMail.zimbra%40mpi-magdeburg.mpg.de

```
Hi everyone! 


Is the following a bug? I am working with git v2.25.1. I hope I won't annoy anyone with a duplicate of an existing/known issue. I'm new to working with mailing lists as well. 

# Problem Description 

I would eventually like to add a submodule to `extern/foo` that is checked out at a particular tag. As I cannot `git clone`/`git submodule add` that tag directly, I have to first checkout the default and then check out the desired tag. If I do so from the repo's base directory, everything works as expected: 
ˋˋˋbash 
git clone <URL> foo 
pushd foo 
git checkout v1.1.1 
popd 
git submodule add ./foo 
ˋˋˋ 
where the last one prints 
ˋˋˋ 
Adding existing repo at 'foo' to the index 
ˋˋˋ 

If, however, I do so with a target directory one level below, i.e. `./extern/foo` instead of `./foo`, 
ˋˋˋbash 
git submodule add ./extern/foo 
ˋˋˋ 
tries to clone `<current remote URL.git>/extern/foo` into `./foo` and fails: 
ˋˋˋ 
Cloning into '/path/to/repo/foo'... 
remote: 
remote: ======================================================================== 
remote: 
remote: The namespace you were looking for could not be found. 
remote: 
remote: ======================================================================== 
remote: 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 
fatal: clone of '<current remote URL.git>/extern/foo' into submodule path '/path/to/repo/foo' failed 
ˋˋˋ 

Using `git submodule add ./foo` from within `extern/` does not work either (`Relative path can only be used from the toplevel of the working tree`). 

# Expected Behavior 

Given the documentation `git submodule --help`, in particular the part of `add` where it says 

> If <path> exists and is already a valid Git repository, then it is staged for commit without cloning. 

I would expect the output 
ˋˋˋ 
Adding existing repo at 'extern/foo' to the index 
ˋˋˋ 

# Current Workaround 

Adding the submodule first and then updating it works: 
ˋˋˋ 
git submodule add <URL> extern/foo 
pushd extern/foo 
git checkout v1.1.1 
popd 
git add extern/foo 
ˋˋˋ 

# Feature Request 

It would be nice if I could do something like `git submodule add -t v1.1.1 <URL> extern/foo`. 


Thanks in advance! 

Jonas

```
