16

I have a project that uses some 3rd Party libraries. So the directory structure is something like:

MY_COOL_PROJECT
   3rdParty
      LIB_1
      LIB_2
   Source
      MY_PROJECT   

The libraries are located in separate repositories. So, if I want to use a git repository for the 3rd Party libraries I can do:

git subtree add --prefix 3rdParty/LIB_1 --squash http://My3rdPartyLibs.com/lib1.git master

However, inside lib1.git repository there is only one bin folder I need. It contains also folders such as documentation, examples, etc. How can I only "connect" my repository with lib1/bin folder instead of the whole repository? Is that even possible?

user2070238
  • 223
  • 5
  • 9
  • 2
    did you find a solution for the sparse subtree? (the current answer doesn't seem to solve it fully) – inger Jun 16 '14 at 01:29

1 Answers1

7

Normally, a git repo is done to be fully cloned/loaded.

You could go for a sparse checkout (Git1.7+), but only if you don't intent to do any modification and push those back. See this example:

$ git init
Initialized empty Git repository in /tmp/si-sandbox/.git/
(master) $ git config core.sparsecheckout true
(master) $ echo message-store/ >> .git/info/sparse-checkout
(master) $ git remote add origin git://github.com/iwein/Spring-Integration-Sandbox.git
(master) $ git pull origin master

The OP user2070238 reports:

This worked with a few changes.
Because, I use submodule I had to use

 echo MY_FOLDER/* >> .git/info/modules/MY_MODULE/sparse-checkout 

And for some reason the MY_FOLDER/ part was not working without *

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks, this worked with a few changes. Because, I use submodule I had to use `echo MY_FOLDER/* >> .git/info/modules/MY_MODULE/sparse-checkout` And for some reason the MY_FOLDER/ part was not working without * – user2070238 Feb 15 '13 at 11:20
  • @user2070238 Excellent. I have included your comment in the answer for more visibility. – VonC Feb 15 '13 at 14:31
  • 2
    The original question was about "git subtree" - this answer covers the sparse checkout instead... at most half of the solution? (maybe not even) – inger Jun 16 '14 at 01:23
  • @inger indeed. subtree wasn't the right tool when it come to selecting only a subfolder of a git repo. – VonC Jun 16 '14 at 05:01
  • @VonC right, but I thought the question wasn't just "selecting a subfolder" of repo. To clarify, I have a big.git repo and lib.git repo. The latter has 2 subdirs "./spam" ad"./stuff". In the big.repo, I'd like to import lib.git using subtree, but only "stuff" not "spam", like this: big/lib/stuff. I thought the OP was asking for this (I may have misunderstood)-anyway, what do you think the best way is for this? my guess is I'd branch off lib.git clean up there, and subtree-add that branch instead. A separate (automated) job would ensure that cleanup branch is up to date with lib.git's master. – inger Jun 16 '14 at 11:43
  • 1
    @inger that would be a good question on its own: I don't know if you can apply a sparse checkout strategy to a subtree merged repo. So branching and cleaning would indeed be more simpler solution. – VonC Jun 16 '14 at 12:50