Creating git submodule without a remote

1.1k views Asked by At

I want to have a sub repo inside my main repo which can push and pull from a completely different remote repo than my main. So I want a submodule. But I want to create the submodule locally, then push it to remote. It does not exist anywhere yet.

All the of the examples I have seen involve pulling a remote repo into a submodule, to the degree that this is how submodules are created to begin with

git submodule add [email protected]:url_to/awesome_submodule.git path_to_awesome_submodule

Is there any way to create the submodule, make some commits, then push them to the remote repo in question?

1

There are 1 answers

0
VonC On BEST ANSWER

Creating git submodule without a remote

No: your submodule must have a remote repo from which it is cloned.

In your case, make sure the root folder of your sub-repo is not tracked:

git rm sub

Then move/delete it, and add it back as a submodule repo:

cd main
git submodule add [email protected]:url_to/awesome_submodule.git sub

From there, you can go in that submodule and:

  • checkout a branch (by default, you are in detached HEAD)
  • make some commit
  • push from it to its own remote URL.