Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Create repo as submodule

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)?

like image 797
manuels Avatar asked Feb 10 '13 17:02

manuels


1 Answers

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
like image 137
William Denniss Avatar answered Sep 21 '22 06:09

William Denniss