I have a git repo in ~/.janus/
with a bunch of submodules in it. I want to add a submodule in ~/.janus/snipmate-snippets/snippets/
, but when I run git submodule add <[email protected]:...>
in the snipmate-snippets
directory, I get the following error message:
You need to run this command from the toplevel of the working tree.
So the question is: How do I add a submodule to the snipmate-snippets
directory?
If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .
You go into ~/.janus
and run:
git submodule add <git@github ...> snipmate-snippets/snippets/
If you need more information about submodules (or git in general) ProGit is pretty useful.
Note that starting git1.8.4 (July 2013), you wouldn't have to go back to the root directory anymore.
cd ~/.janus/snipmate-snippets git submodule add <git@github ...> snippets
(Bouke Versteegh comments that you don't have to use /.
, as in snippets/.
: snippets
is enough)
See commit 091a6eb0feed820a43663ca63dc2bc0bb247bbae:
submodule: drop the top-level requirement
Use the new
rev-parse --prefix
option to process all paths given to the submodule command, dropping the requirement that it be run from the top-level of the repository.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.Signed-off-by: John Keeping
Depends on commit 12b9d32790b40bf3ea49134095619700191abf1f
This makes '
git rev-parse
' behave as if it were invoked from the specified subdirectory of a repository, with the difference that any file paths which it prints are prefixed with the full path from the top of the working tree.This is useful for shell scripts where we may want to
cd
to the top of the working tree but need to handle relative paths given by the user on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With