Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Clone Into Another Existing Git Repo

Tags:

git

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!

like image 347
botbot Avatar asked Apr 28 '12 03:04

botbot


People also ask

Can you clone a git repo into another repo?

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 . That means cloning the enclosing repo, and you will get an empty " lib/ " folder.

What happens if you clone an existing git repository?

When you clone a repository, you copy the repository from GitHub.com to your local machine. Cloning a repository pulls down a full copy of all the repository data that GitHub.com has at that point in time, including all versions of every file and folder for the project.

How do I clone a repository to another GitHub?

Navigate to the repository you just cloned. Pull in the repository's Git Large File Storage objects. Mirror-push to the new repository. Push the repository's Git Large File Storage objects to your mirror.


1 Answers

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").

like image 157
VonC Avatar answered Oct 05 '22 12:10

VonC