Crissov
Crissov

Reputation: 1059

Can a git submodule be restricted to a single resource?

There are two complex projects and my newly created one, for the sake of simplicity all hosted on Github, say

Within my project, I only need a single subtree from the first repository (i.e. a folder and all files in it), say ./assets/img/, and a single file from the second one (each from their main branch), say ./data/names.json. Both will be updated from time to time.

As far as I understand the documentation on the .gitmodules file and the git submodule command, there is no way to directly achieve this. That means the following (or something like it) won't work:

[submodule "assets"]
  path = images/vendor
  url = git://github.com/vendor/asset.git:/assets/img/

[submodule "metadata"]
  path = standard-names.json
  url = git://github.com/standard/metadata.git:/data/names.json

What is the best practice here? Can I put the submodules in a hidden folder and create symlinks in the places I want?

images/vendor       -> .ext/vendor/assets/img/
standard-names.json -> .ext/standard/data/names.json

Upvotes: 0

Views: 525

Answers (1)

qräbnö
qräbnö

Reputation: 3031

Can a git submodule be restricted to a single resource?

No, clone = hole repo with one or more branches.

What is the best practice here?

Dunno, but I found: https://stackoverflow.com/a/18590081/2093187

Can I put the submodules in a hidden folder and create symlinks in the places I want?

Yes, see link above.


Another approach would be to modify your git (status) command with

git()
{
    if [[ $# -ge 1 && "$1" == "status" ]]
    then
        echo Your git-status pre-hook…
        # wget -O destination url
        curl -o destination url
    fi

    command git "$@"
}

Put it in .bashrc (or .bashrc. on windows).

Upvotes: 1

Related Questions