Creating git submodule without a remote
Asked Answered
R

1

7

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?

Rachele answered 21/9, 2018 at 16:26 Comment(0)
M
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 [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.
Mealtime answered 22/9, 2018 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.