Aurimas
Aurimas

Reputation: 2727

How to setup git to checkout a folder of another repo into my repo subdirectory?

In our project, one person is writting plain SCSS, and other people are working on Rails app. I regulary have to copy the SCSS from the simple repo into the Rails asset pipeline. The copy is exact. So I would like to know how to setup git so that I could do it on a regular basis? (as convenient as possible)

Upvotes: 0

Views: 44

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45749

Well, I guess git submodules is the feature you're looking for. See the git documentation at https://git-scm.com/book/en/v2/Git-Tools-Submodules

If I sound a little hesitant, it's because I've always thought it was a bit odd to pull in dependencies with the source control software; if you could automate this through your build tools I think it might be a more natural solution. But if doing it as a git operation is the way to go for you, I'd look at the above.

UPDATE

Follow-up question from comments: Can a submodule be set up for just a sub-folder of the other project?

So we have project A

projectA/
    stuff/
    other-stuff/
    shared-stuff/

and project B

projectB/
    more-stuff/
    unrelated-stuff/

and we want projectA/shared-stuff to show up also as projectB/shared-stuff/ and we're talking about how to do this with submodules.

I don't know that a submodule can be any more specific than "embed this commit of that repo". But one suggestion would be to split the shared code into its own repo

shared-stuff/

Then add shared-stuff as a submodule of both project A and project B

projectA repo       | shared-stuff repo |  projectB repo
==================================================================
/                   |                   |  /
    stuff/          |                   |      more-stuff/
    other-stuff/    |                   |      unrelated-stuff/
    (shared-stuff)--> /                 <--    (shared-stuff)

Of course because submodule mappings are contained within the repo using the submodule, the folder names (or locations in the parent projects' trees) don't have to match...

Upvotes: 1

Related Questions