Git Submodule Examples
doit
Posted on October 8, 2022
Git Submodule
- add remote repo into existing repo
- add existing repo folder as submodule
What is submodule
In short, one git repo includes other git repos.
codespace (git repo, private)
├── Archived_projects (git repos)
└── Projects
├── project-foo (git repo)
└── project-bar (git repo)
add remote repo into existing repo as submodule
git submodule add https://github.com/qdriven/fluentqa-monorepo.git daily-toolkits/fluentqa-monorepo
the change now is in the .gitmodule file
[submodule "daily-toolkits/fluentqa-monorepo"]
path = daily-toolkits/fluentqa-monorepo
url = https://github.com/qdriven/fluentqa-monorepo.git
add existing repo folder as submodule
Sometimes, there are already some github repo in a existing repo
> ls -al
total 24
drwxr-xr-x 7 patrick staff 224 10 8 11:50 .
drwxr-xr-x 18 patrick staff 576 10 8 11:50 ..
-rw-r--r--@ 1 patrick staff 6148 9 25 10:32 .DS_Store
-rw-r--r-- 1 patrick staff 304 9 25 10:51 README.md
drwxr-xr-x 14 patrick staff 448 9 24 16:24 fluent-project-templates
drwxr-xr-x 15 patrick staff 480 10 8 11:50 fluentqa-monorepo
fluent-project-templates is a git repo, and how to add fluent-project-templates into the parent git repo
- add existing repo to .gitmodules file
git submodule add https://github.com/qdriven/gathering.git daily-toolkits/python-gathering
- check .gitmodules file, new submodule is added
[submodule "path/to/submodule1"]
path = path/to/submodule/1
url = git@github.com:user/submodule1
- run command
git submodule sync
- commit files
git add .
git commit -m "add submodules"
git push
💖 💪 🙅 🚩
doit
Posted on October 8, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.