1

I have a git repository in folder AAA and then another git repository in folder BBB.

What I need to do is to create a new folder in AAA where I would copy BBB repository, so it would become a subfolder of AAA.

The result should be that AAA repository stays as it is and excludes BBB folder, while when I enter the BBB folder it's a new repository of its own that has nothing to do with AAA.

Could you please explain me how to do that?

As I understand, I probably could create subfolder BBB in AAA then add it to .gitignore and then initialize a new repo there? Right? How would I do that? Thank you!

Aerodynamika
  • 7,883
  • 16
  • 78
  • 137
  • you should look at git submodules. They are moderately complicated though, so a post on stack overflow might not be the best place for it. here is a link I like that explains it well: https://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/. – DrCord Mar 05 '15 at 21:30
  • Looks like a repeat of this [question](http://stackoverflow.com/questions/4659549/maintain-git-repo-inside-another-git-repo). – Ryen Nelsen Mar 05 '15 at 21:32
  • Possible duplicate of [Maintain git repo inside another git repo](https://stackoverflow.com/questions/4659549/maintain-git-repo-inside-another-git-repo) –  Sep 15 '18 at 20:26

1 Answers1

3

This is the absolute minimum that you would need to do

git init AAA
cd AAA
echo BBB > .gitignore
git init BBB

For most scenarios submodules is a better solution. But if you want the repositories to be completely independent of each other, this is a way to do it.

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
  • Thanks! you think it's better than using Submodules? – Aerodynamika Mar 05 '15 at 21:34
  • 1
    It's different, if you want the git repos to know about each other then you need to use a submodule. If you want them to purposely not know about each other this is a perfect, simple answer for that. – DrCord Mar 05 '15 at 21:35
  • @deemeetree no, I think submodules are a far better solution. With them the AAA repository will point to a version in BBB, which is probably what you want. – Klas Mellbourn Mar 05 '15 at 21:35
  • 1
    @KlasMellbourn in fact no, I don't want AAA to be aware of BBB. Is gitignore better then for that case? – Aerodynamika Mar 05 '15 at 21:36