Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`--name` option doesn't work with `git submodule add` command

I want to add a git submodule with different name like:

git submodule add --name foo [email protected]:ironsand/cookbook-foo.git 

I wanted to create a git submodule directory named foo, but the repository are created with the name cookbook-foo.

Most likely I'm doing something wrong, but I don't know what was wrong.

How can I change the name of git submodule directory?

like image 317
ironsand Avatar asked Oct 06 '14 11:10

ironsand


People also ask

How do I add a submodule to a git repository?

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.


1 Answers

Don't conflate the path and the name of a submodule. You want to run

git submodule add [email protected]:ironsand/cookbook-foo.git foo/ 

instead. For more details, see the git-submodule man page; the relevant git-submodule syntax here is

git submodule [--name <name>] <repository> [<path>] 

where...

  • <repository> is the URL of the new submodule's origin repository.
  • <path>, if specified, determines the name of the subdirectory (of the superproject's root directory) to receive the clone of the repo living at <repository>; if left unspecified, <path> defaults to the name of that repo.
  • <name> is the submodule's name, i.e. the name that appear in the corresponding submodule entry in the .gitmodules file; if left unspecified, <name> simply defaults to <path>.

Here is a toy example to fix ideas:

$ cd ~/Desktop $ mkdir test $ cd test $ git init $ git submodule add --name brutus https://github.com/bradfitz/gitbrute bradfitz_bruteforce $ ls -a .           .git            bradfitz_bruteforce ..          .gitmodules $ cat .gitmodules [submodule "brutus"]     path = bradfitz_bruteforce     url = https://github.com/bradfitz/gitbrute 
like image 87
jub0bs Avatar answered Sep 19 '22 17:09

jub0bs