orome
orome

Reputation: 48446

Can I have a single git repository that spans several isolated directories?

I have a project that has components in several different directories and would like to treat the contents of those folders as a single git repository.

For example, I have something like

  • A
    • a
    • b

and elsewhere

  • 1
    • i
    • ii

and would like to combine them in a single git repository:

  • repo
    • A ..
    • 1 ..

Can I do this with git?

Upvotes: 4

Views: 209

Answers (3)

GoZoner
GoZoner

Reputation: 70135

If 'A' and '1' already have their own git repositories and if you want to continue using those repositories then your only choice is to create a git repository in 'repo' and then add 'A' and '1' as git submodules.

If you don't care about existing git repositories in 'A' and '1' then just create a new git repository in 'repo' and add all the contents of 'A' and '1'.

Upvotes: 0

tripleee
tripleee

Reputation: 189327

If you think about it, most source distributions are structured like this. That is, the repo layout does not reflect the deployment layout. There is source code in src, which ends up compiled maybe in build, and those artefacts in turn are installed somewhere like /usr/bin. Probably there is a manual, which is assembled by a different toolchain, and installed elsewhere on the target system. There may be a web site, which is deployed by completely different means, to a different target system, etc. To manage all of this, there is a suite of build and deployment scripts, some of which are (stupidly) not always tracked along with the rest of the system.

However, none of this helps much, other than as a mental model, if you cannot find deployment tools for your particular scenario.

If you need to build your own deployment script, you can probably start with something fairly simple. With the limited background you have provided, it sounds like you might not need much more than

while read repo path; do
    cd "$path"
    mkdir "$repo"
    cd "$repo"
    git init
    git pull /path/to/repo/"$repo"
done<<____HERE
    A /var/www
    1 /srv
____HERE

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363517

No, you can't. Git is designed to track the contents of a single directory hierarchy. The simple solution is to move all these directories into a common superdirectory. An alternative is to make several repos and then combine them using submodules.

Upvotes: 5

Related Questions