I'd like to create a new repository as a submodule of my project.
Usually, I create a Github repo and then add it as a submodule using the command
git submodule add url_to_repo.git
Is there a way to create a new repo directly as a submodule without creating the repo somewhere else first (neither locally nor remote e.g. on Github)?
Easy! Say submodule_dir
is the name of the directory you wish to submodule-ize (assuming it's not already under git control).
cd submodule_dir
git init
git add .
git commit
# on github, create the new repo, then:
git remote add origin [email protected]:your_username/your_repo_name.git
git push -u origin master
cd ..
mv submodule_dir submodule_dir_delete_me
git submodule add [email protected]:your_username/your_repo_name.git submodule_dir
Later (once you're happy)
rm -rf submodule_dir_delete_me
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