Skip to content

Instantly share code, notes, and snippets.

@attitude
Created September 18, 2013 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attitude/6611667 to your computer and use it in GitHub Desktop.
Save attitude/6611667 to your computer and use it in GitHub Desktop.
Reusing of single library component in your project with Git `read-tree`

Here is a quick tip on pulling dependencies in your project using git read-tree command.

The Problem

How to use a single component from some library (eg. Form from Symfony), but not the whole library (tried the git submodule ?).

  1. Init project:

    Create a new project and init Git:

    $ mkdir newproject
    $ cd newproject
    $ git init
    
  2. Setup remote:

    You need to setup a remote (right now don't know how to skip the step) otherwise you would get a fatal: Not a valid object name error.

    $ git remote add -f symfony git@github.com:symfony/symfony.git
    
  3. Import only the subdirecory subtree:

    $ git read-tree --prefix=src/Symfony/Component/Form/ -u symfony/master:src/Symfony/Component/Form
    
  4. Pull in new changes:

    Pulling in changes might be as easy as repeating same steps over and over again but a better workflow should be proposed.

Any thoughts on pull/push are appreciated.

@martin_adamko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment