5

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 git@github.com: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?

Wapiti
  • 1,851
  • 2
  • 20
  • 40

1 Answers1

4

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 git@github.com: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.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250