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?
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-treeon the directory:And you might want to have a look at git-subtree, which wraps up a lot of this stuff in a nice friendly way.