1

I have a remote repository with several sub-directories like so:

/Client1
/Client2
/Server

I would like to create a local repository that only pulls one of these sub-directories (Server), and only pushes back changes to this directory. How can I do this?

I know I could split these sub-directories into multiple git repositories, but I'm trying to find a way to avoid changing the structure of the remote repository.

John
  • 1,440
  • 1
  • 11
  • 18
  • It seems that what you want is "sparse checkout" described here http://stackoverflow.com/questions/180052/checkout-subdirectories-in-git. – Restuta Nov 14 '16 at 07:06

1 Answers1

1

You should use submodules for this purpose.

Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.


git submodule

Break your big project to sub projects as you did so far.
Now add each sub project to you main project using :

git submodule add <url>

Once the projected is added tot your repo you have to init and update it.

git submodule init
git submodule update
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Interesting- that's not quite what I'm looking for, because I do have to create three additional repositories, and then re-create the original, but maybe that's the way I'll have to go. – John Nov 15 '16 at 04:13