Search code examples
filegithubclonerepository

Pull down a file from a remote repo during a clone of your own


I've had a look at one or two similar questions on Stack Overflow, but they don't address what I am looking for exactly, unless I've missed it somewhere.

What I have is my own repo that contains custom boilerplate code. In my repo I'd like to include files from various other remote repo's (not my own). Thus when I'm ready to work on a new project, I can clone my repo, get my boilerplate code, as well as the files from the various other repo's I usually go to manually and download from. This way preferably the up to date versions are pulled as opposed to just copying these files into my own repo and having to update them every time there is a revision.

Is this possible to do simply using Git/GitHub?


Solution

  • Submodule is the way to include other repos.

    And you now can define a submodule to follow a branch (git 1.8.2+), which means this will bring you the latest commits of said branch.

    git submodule update --remote
    

    I do that in my compileEverything GitHub repo, where I include the latest from Semantic-UI master branch.

    That is because my .gitmodules looks like:

    [submodule "Semantic-UI"]
            path = Semantic-UI
            url = https://github.com/jlukic/Semantic-UI
            branch = master
    

    I'm not particularly looking to include an entire repo/branch but just a select few files within one.
    Example: Normalize.css Still possible to do?

    No. It is best to:

    • include the full repo through a submodule (since the submodule pointer itself hardly takes any place in your repo)
    • keep in the parent repo symlinks to the files you need from that submodule.

    That way, you see:

    • the files you want (symlinked to the same files from the subrepo)
    • the subrepo reference, that you can update at will.