l0b0
l0b0

Reputation: 58768

Clone part of Git repo in another repo

I've got one repo which contains some utility functions in a single file. I'd like to somehow add that file to another repo, keeping the link to the old one (so I can push/pull to keep up to date with it), while keeping all the other files out. The goal is that someone who pulls the second repository should also get the utility functions without having to fiddle with multiple repos. Is this doable for example with cherry-pick or some special remote/clone syntax, or do I have to move the utility functions to a separate repo?

Edit: Looks like Partial sharing of git repositories and GitHub's Working with subtree merge could be relevant; checking up on them.

Edit 2: After reading about subtree merge, it seems like that'll do the job, if I can just find the "id of the tree object(s) to be read/merged", as mentioned by git help read-tree. Is that just a commit ID?

Upvotes: 1

Views: 1884

Answers (1)

Cascabel
Cascabel

Reputation: 496742

Tree objects are not the same as commits. A tree object essentially represents a directory. A commit will contain a tree representing the work tree; that tree may contain other trees (subdirectories) as well as blobs (content of files).

You can find the tree SHA1 you need using git ls-tree on the directory:

$ git ls-tree HEAD Documentation/howto
040000 tree 7f4e8e870f2e4e7682a344e9a305f065388553e2    Documentation/howto

And you might want to have a look at git-subtree, which wraps up a lot of this stuff in a nice friendly way.

Upvotes: 2

Related Questions