0

I have n repositories with content that I would like to make available in a directory of my server. The server directory will be dynamically scanned for content for to work with that content.

However, I would like to keep the repositories which I like to import as they are. I do not want to merge or perform any one-way tasks. The source repositories really should remain independent.

When I git pull on my server directory, I'd like to update all those files that I subscribed to. Note that it does not have to be git pull but you get the idea of what I mean.

This is what it should look like (there are more files and repositories, it's just an example):

- github
    - repo 1 with 10 files
    - repo 2 with 5 files
- server
    - content-directory
          - 2 files "subscribed" out of repo 1
          - 1 file "subscribed" out of repo 2

Changes on github's repositories should be applied to the server-directory files as soon as I do something like git pull in there.

Is there a simple way of doing this?

My approach: Create clones of those repositories in content-directory but then I would get the whole repo although I only want some files. .gitignore prevents from uploading but not from downloading.

Maybe there already is a good way that I just do not know.

Xiphias
  • 4,468
  • 4
  • 28
  • 51

1 Answers1

3

As far as I know there is no native Git functionality for this, but you can probably get the results you want using symlinks, which are available on POSIX systems but also on Windows with NTFS.

I'll be assuming a Linux system here.

Check your repositories out somewhere outside of your content directory:

$ cd /some/directory/repos
$ git checkout https://github.com/user/repo-a.git
$ git checkout https://github.com/user/repo-b.git
$ ls
repo-a/ repo-b/

Now, link the files you want from each repository into your server's content directory:

$ cd /path/to/server/content/directory
$ ln -s /some/directory/repos/repo-a/file1 .
$ ln -s /some/directory/repos/repo-a/file2 .
$ ln -s /some/directory/repos/repo-b/file1 file1b

The files show up in the directory, but if you use a long listing (-l) you can see that they're really links to other files:

$ ls
file1 file1b file2
$ ls -l
file1 -> /some/directory/repos/repo-a/file1
file1b -> /some/directory/repos/repo-b/file1
file2 -> /some/directory/repos/repo-a/file2
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    In combination with this solution, you can use [sparse clone](http://stackoverflow.com/a/13738951/495796) to get only the directories you want. – Robin Green Jan 04 '14 at 14:45