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?

1
  • 4
    did you find a solution for the sparse subtree? (the current answer doesn't seem to solve it fully) Commented Jun 16, 2014 at 1:29

1 Answer 1

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 *

Sign up to request clarification or add additional context in comments.

6 Comments

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 Excellent. I have included your comment in the answer for more visibility.
The original question was about "git subtree" - this answer covers the sparse checkout instead... at most half of the solution? (maybe not even)
@inger indeed. subtree wasn't the right tool when it come to selecting only a subfolder of a git repo.
@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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.