9/27/2023 0 Comments Git clone tag# -remote will also fetch and ensure that Subsequent update for that submodule will have to use the -remote option: # update your submodule Git commit -m "Make submodule tracking a branch" ![]() Usually, it is 'origin')ĭon't forget to record the new state of your submodule in your parent repo: cd /path/to/your/parent/repo (with 'origin' being the name of the upstream remote repo the submodule has been cloned from.Ī git remote -v inside that submodule will display it. Git checkout -b branch -track origin/branch ![]() Make sure your submodule is actually at the latest of that branch: cd path/to/your/submodule Make sure the parent repo knows that its submodule now tracks a branch: cd /path/to/your/parent/repo Note that if you have an existing submodule which isn't tracking a branch yet, then ( if you have git 1.8.2+): (Git 2.22, Q2 2019, has introduced git submodule set-branch -branch aBranch - ) gitmodules file and gives you the option to update the submodule object to the latest commit of a specified branch before populating it. It is simply adds information about a branch in the. Git submodule add -b is not some magically way to keep everything up to date with a branch. Since you have now updated the commit the submodule object is pointing to, you have to commit the changed submodule object into your Git repository. This can be done in two steps by djacobs7 answer. Instead of populating the content of the submodule to the commit pointed to by the submodule, it replaces that commit with the latest commit on the master branch, THEN it populates the submodule with that commit. The only thing that the -b option buys you is the ability to add a -remote flag to your update as per Vogella's answer: git submodule update -remote The submodule object is still pointing at a specific commit. SubmoduleTestRepo, and you do not need to change the. gitmodules file, but SHA and TAG are not supported! (instead of that, the branch's commit of each module can be tracked and updated using " git add. Note: only branch name is supported in a. So following the same example, it would look like this: Now, all the -b does is add one line in your. It knows where to find the commit because of the information in the. Whenever you do a git submodule update, it will populate your submodule with content from the commit. Git submodule objects are special kinds of Git objects, and they hold the SHA information for a specific commit. Or do git submodule status from a command line. GitHub shows these as "submodule" objects. You have a submodule object (named SubmoduleTestRepo in this example) in your Git repository. You know you have a Git submodule when you have these two things. (where branch_name is the name of either a branch or a tag).I'd like to add an answer here that is really just a conglomerate of other answers, but I think it may be more complete. ![]() ![]() (AFAIK, that only works with npm though it doesn't work with git clone the way you asked about.)įor completeness's sake, if you really wanted to clone just a particular version (copying only that version from the remote to your local machine), you could do something like git clone -depth 1 -b branch_name In the case of npm, you can add a commit identifier (branch, tag, commit SHA, etc.) to the end of the URL as a hash fragment. You can change which version is checked out with the -b option (or, of course, you can just check out the desired version after the clone completes).īut there are scenarios where that's not practically useful advice, such as if you're using npm to fetch something from Git (so you don't directly issue a clone command). With Git you usually don't clone a particular version you clone the entire repository - making a local copy of the every version - and then checkout a specific version.īy default when you clone, a specific version (usually master) is checked out.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |