1

Following this answer on SO- I understand that following git 1.8.4, submodules can be added from anywhere ( not just toplevel). I'm on git version 2.7.4 and when I do:

git submodule add ../../../functest

I get:

Relative path can only be used from the toplevel of the working tree

I'm in opnfvdocs/docs/submodules. I want to add opnfvdocs/functest inside opnfvdocs/docs/submodules such that I have relative path in .gitmodules

The tree structure is:

github.com/OPNFV
|-opnfvdocs
|-functest

Am I missing something?

Community
  • 1
  • 1
FlyingAura
  • 1,541
  • 5
  • 26
  • 41
  • You might want to read your link more closely... "Since the interpretation of a relative submodule URL depends on whether or not "remote.origin.url" is configured, ***explicitly block relative URLs in "git submodule add" when not at the top level of the working tree***." – jthill Dec 16 '16 at 07:10
  • So this means I have to configure `remote.origin.url` to point at `OPNFV`? – FlyingAura Dec 16 '16 at 07:18

1 Answers1

3

To create a submodule at a specific path, stay at top level, and provide the path as last argument:

opnfvdocs$ git submodule add ../functest docs/submodules/functest
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • @flyingaura: Tested with 2.37.1, works. Please consider accepting the answer. – DarkTrick Apr 05 '23 at 09:06
  • As of october 2022, you may get the error `fatal: transport 'file' not allowed`. Use `git -c protocol.file.allow=always submodule add ../functest docs/submodules/functest` instead. [Details (security implications!) here](https://vielmetti.typepad.com/logbook/2022/10/git-security-fixes-lead-to-fatal-transport-file-not-allowed-error-in-ci-systems-cve-2022-39253.html) – TamaMcGlinn Aug 22 '23 at 14:15