Git Clone Into Another Existing Git Repo

Git

Git Problem Overview


Am I going to run into any issues if I git clone a repo into an existing git repo?

For sake of simplification, I am developing a library "lib/" that should be available to all of my projects. This is a separate git repo. I'd like to import this lib/ into all of my projects, and update it only in one place, never touch it from any of the projects, just use it.

I am assuming this is ok, just wondered if there is anything I should watch out for. Thanks!

Git Solutions


Solution 1 - Git

Just for the record, you can clone a git repo within another one:
Everything under your lib directory will be ignored by the enclosing Git repo, because said lib directory contains a .git.

So it would work, but the enclosing repo would have no idea:

  • it needs a lib directory from another repo
  • it needs a specific revision of that lib to build properly, even though it would record the SHA1 of the nested lib repo tree. (that is a gitlink, a special entry in the index of the parent repo)
    That means cloning the enclosing repo, and you will get an empty "lib/" folder.

Those (repo URL and repo SHA1) are precisely the two informations recorded by the parent repo (the enclosing one) in order to reference a submodule.
It is made to give you access to a fixed revision of another repo within your repo, but as explained in "True nature of submodules", that doesn't prevent you to locally modify lib directly within your parent repo.
(As long as you commit your modifications in lib first, then go one level up back in your parent repo, and commit there as well)

The main benefit to any contributor of your main project is that, when they will clone said project, they will know they also need lib if it is declared as a submodule (as mentioned in "Git Submodule Workflow Advice").

Solution 2 - Git

I'm finding that following this tutorial is helpful for understanding submodules if you don't have much prior experience.

http://help.github.com/submodules/

https://chrisjean.com/git-submodules-adding-using-removing-and-updating/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbotbotView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitbotbotView Answer on Stackoverflow