DEV Community

doit
doit

Posted on

1

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

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (0)

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay