0

I have two GIT repositories and I would like to be able to sync only some of the directories (and their subdirectories) at a time.

Let's say I have two repositories containing the same directories tree as they started from a single base:

repo1/.git
repo1/A/file1
repo1/A/a/file2
repo1/B/file3
repo1/B/b/file4

repo2/.git
repo2/A/file1
repo2/A/a/file2
repo2/B/file3
repo2/B/b/file4

git pull from repo1 to repo2 would bring the changes in all the files. Instead of that, I would like for example to sync only the files below the A directory (file1 and file2) from repo1 into repo2 without syncing the files below the B directory (file3 and file4). Files below the B directory could be still be synced later on.

Is this somehow possible? How can I do that?

Thanks in advance for your answer(s).

Cyril Klec
  • 11
  • 3

1 Answers1

0

I believe this boils down to fetching the other repo, then checking out the specific files only. Something like this must do:

git fetch repo2
git checkout -m FETCH_HEAD A/file1 A/file2
git add A/file1 A/file2
git commit

You can find more on this here.

Community
  • 1
  • 1
Tamas Rev
  • 7,008
  • 5
  • 32
  • 49
  • Thanks Tamas. Would that merge changes in the files or only overwrite them? Actually I need a merge (like what happens in a pull). – Cyril Klec Apr 04 '17 at 13:57
  • ok great, I will test this out. Do you have also a solution without naming the files explicitely and that will take care as well of removing files that were removed in the other repo? – Cyril Klec Apr 04 '17 at 14:14
  • Unfortunately, I don't think I have such command right away. You can try though to checkout the directory only: `git checkout -m FETCH_HEAD A` – Tamas Rev Apr 04 '17 at 14:33
  • Thank you! Running git checkout on a directory is supposed to be recursive? – Cyril Klec Apr 05 '17 at 11:57