vfclists
vfclists

Reputation: 20211

How does git handle the placement of a git repository inside another?

I have been reading an article in which the author instructed: creating a new repository within an existing one, and wondered if it was an error he overlooked. I will verify with him later.

These are the conditions I want to check:

  1. The condition when an existing directory is made into a repository, and files already checked into the main project are also checked in the new (sub) repository. Is this possible?

  2. When a directory tree which contains git repositories is checked in for the first time

  3. When a new empty repository is created under the repository, either by git init, or by copying a .git repository into a new or empty directory?

Upvotes: 2

Views: 166

Answers (2)

VonC
VonC

Reputation: 1324673

As mentioned in "Git repository in a git repository", the nested repo is mostly ignored by the parent repo (only a gitlink is recorded)

So any operation on the parent repo won't have an incidence on the nested repo.

If you declared the nested repo as a submodule though, then you can checkout the parent repo and the nested repo, but that submodule will always reference a fixed commit.
If you make any modification in the submodule, you need to commit them, push them and go back to the parent repo, commit and push (to record the new fixed commit of the submodule).
See "True nature of submodules".

Upvotes: 2

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72755

If you want to do this, you should use submodules if you want to have nested repositories. The top level repository will track the latest commit of all the sub repositories and inside them, things can be as you wish. Without this, git will behave in undocumented and unsupported ways so you should probably not try it.

Upvotes: 1

Related Questions