Git Submodule Examples

qdriven

doit

Posted on October 8, 2022

Git Submodule Examples

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)
Enter fullscreen mode Exit fullscreen mode

add remote repo into existing repo as submodule

git submodule add https://github.com/qdriven/fluentqa-monorepo.git daily-toolkits/fluentqa-monorepo
Enter fullscreen mode Exit fullscreen mode

asciicast

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

fluent-project-templates is a git repo, and how to add fluent-project-templates into the parent git repo

  1. add existing repo to .gitmodules file
git submodule add https://github.com/qdriven/gathering.git daily-toolkits/python-gathering
Enter fullscreen mode Exit fullscreen mode
  1. check .gitmodules file, new submodule is added
[submodule "path/to/submodule1"]
    path = path/to/submodule/1
    url = git@github.com:user/submodule1
Enter fullscreen mode Exit fullscreen mode
  1. run command
git submodule sync
Enter fullscreen mode Exit fullscreen mode
  1. commit files
git add .
git commit -m "add submodules"
git push
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
qdriven
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.

Related