Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add submodule of only a certain branch

Is it possible to only checkout a single branch as a submodule WITHOUT the overhead of the whole repository in my main repositories working directory? (And really only download the files of that branch)

I think of having a submodule for a javascript library with a branch called "dist" containing only the minified compiled ready-to-use js file. The "master" would instead contain the source files and a bunch of other stuff only needed for development of the lib.

like image 683
Danny Raufeisen Avatar asked Nov 19 '25 08:11

Danny Raufeisen


1 Answers

Note that a submodule only represents a fixed SHA1.

That being said, on git submodule update --remote, you can make a submodule change its SHA1 by the latest of a given branch by following my answer "git submodule tracking latest"

For an existing submodule:

git config -f .gitmodules submodule.<path>.branch <branch>

A repo can add itself as a submodule, with a given branch.
I used to do so for the gh-pages of a GitHub pages repo.

Since a submodule is a sub-repo, you will download the repo, and only checkout the branch you need.
Although, there is a --single-branch option to git clone which does limit the clone to a single branch.
You can try and add again your submodule with the -b (git submodule add -b abranch) option to check that is did clone the remote submodule repo with only that one branch in it.
See "Is a full clone the only way to submodule add a branch?".

like image 179
VonC Avatar answered Nov 21 '25 10:11

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!