Reputation: 993
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.
Upvotes: 3
Views: 7748
Reputation: 1115
Adding Submodule Branch(Submodule1Branch) inside MainProjectBranch In Same Repository Process :-
Create Branch of Submodule(treated as Repository):-
Create 1 Branch as Submodule1Branch from Master.
Clone Submodule1Branch in your local machine and delete everything of Master in it and push with respective Project of Submodule1Branch only by given commands:-
git status
git add .
git commit -m “Deleted everything of Master Project and loaded with my submodule project data“
git push
Add this Submodule1Branch as a Submodule of your MainProjectBranch in same repo:-
Result :- You may go one bitbucket or git server and check MainProjectBranch there you will find Submodule1Branch as submodule of MainProjectBranch.
Note:- You can perform same above steps for separate repositories as well .(Ex:- submodule repo will be different and main project repo will be different). Happy coding!! :).
Upvotes: 0
Reputation: 1323293
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?".
Upvotes: 2