Today I learned how to create nested git repositories through the
I'm working on my Textual tutorial for EuroPython 2023 and I am saving all the tutorial materials (code, slides, instructions, etc) in a GitHub repository under my company's organisation.
The repository lives under my company because I am giving the tutorial in their name. However, I would still like to show that tutorial on my talks repository. So, I thought “Wouldn't it be nice if I could nest git repositories and just list the tutorial repository under my talks repository?”.
As it turns out, you can nest git repositories!
To nest a repository inside another one, you use the command
git submodule add.
When you add the nested repository, that git refers to as a “submodule”, you need to specify the URL of the original repository, so that git can point to it.
Suppose that you have two repositories,
child, and you want to nest
Here is how you could do this:
# Open the `parent` folder. ~:$ cd parent # Clone the `child` inside the parent. # This will create a folder `child` inside `parent`. # (The child sub-repo can be inside a folder with a different name.) ~/parent:$ git clone https://github.com/xxx/child # Add that folder as a submodule linked to a repo at a given URL. # (This creates a new file `.gitmodules`.) ~/parent:$ git submodule add https://github.com/xxx/child child # repository URL ^ local path for the repo ^^^^^ # Commit & push the submodule. ~/parent:$ git commit -m "Add child submodule." ~/parent:$ git push
That's all it takes! Quite neat, hun? If I learn other useful things about submodules I will let you know.
That's it for now! Stay tuned and I'll see you around!
If you enjoyed this blog article, you will love the mathspp insider 🐍🚀 newsletter! Join +16.000 others who are taking their Python 🐍 skills to the next level! 🚀