When you add a submodule in Git, you don't add the code of the submodule to the main repository The article is misleading and contains many mistakes.īelow the mistakes I found, with the corrections of them: Git config -global alias.pull-all 'pull -recurse-submodules' This will pull the main repository and also it's submodules.Īnd you can make it easier with aliases: git config -global alias.clone-all 'clone -recurse-submodules' This will clone a repository and also check out and init any possible Fortunately, there are some tricks to make it easier: git clone -recurse-submodules It is sometimes annoying if you forget to initiate and update your With submodules, don't forget to keep your submodules up-to-date. So Git sees this as a change, butĪctually you just didn't update the submodule's code. This is notīecause you changed the submodule's code, but because its code isĬhecked out to a different commit. The submodule, it would say HEAD detached at. Submodule in the Changes not staged for commit list with the text If you don't run this command, the code of your submodule is checked What happens if you don't run this command? Submodule has submodules itself, you can add the -recursive flag to If a submodule is not initiated yet, add the -init flag. To update theĬode of your submodules, you should run: git submodule update Information that the submodule is pointing to anotherĬommit, but doesn't update the submodule's code. Git pull, because with git pull it only retrieves the If someone updated a submodule, the other team-members should update If someone else updated the submodule pointer git checkout the branch/commit you want to point to.Update the submodule pointer to a different commit When you git commit in the main repository, it will update the.In git diff you'll see the old and new commit pointers.In git status you'll see that the submodule directory is modified.The next sections describe different scenarios on doing this. To this new commit, you should create another commit in the main Of the submodule is checked out on a different commit than the main Has the text (modified content) behind it. The main repository, will show Changes not staged for commit and it If there are changes in the submodule's repository, then git status in You make new commits inside a submodule, the main repository will It use the new commit of the repository of the submodule. Repository know that you've updated the submodule's repository, and make In a regular Git repository (just execute the git commands in the To it, you should make the changes in its repository and push them like The submodule is just a separate repository. This is notĪutomatically done by git clone. If you've cloned a repository that makes use of submodules, you shouldĪlso run this command to get the submodule's code. This will pull all the code from the submodule and place it in the Then you'll have to initiate them with: git submodule init If there are new submodules you'll see it in the output of Information about the submodule, this is retrieved by a normal If a new submodule is created by one person, the other people in the When you commit and push these files you commit/push Master branch) at the time this command is executed.Īfter this operation, if you do a git status you'll see two files in Which will be the current commit of the default branch (usually the This submodule, which contains the commit the submodule points to, With default configuration, this will check out the code of theĪwesome_submodule.git repository to the path_to_awesome_submoduleĭirectory, and will add information to the main repository about You can add a submodule to a repository like this: git submodule add path_to_awesome_submodule Work with the latest commit of the submodule, it prevents unexpected This is good, because your code might not Submodule's code won't automatically be updated if the submodule's This informationĭescribes which commit the submodule is pointing at. Submodule that is added to the main repository. Submodule to the main repository, you only add information about the When you add a submodule in Git, you don't add the code of the This is a lot more convienient than copy-pasting the code into the With this approach you can easily update that sharedĬomponent in all the repositories that added them as a submodule. Useful if you have multiple repositories that share a commonĬomponent. Re-use the submodule in multiple parent repositories. This way you'll have aĬleaner Git log, because the commits are specific to a certain You can make every subproject a submodule. Useful if you have a big project that contains multiple subprojects. Separate big codebases into multiple repositories. Repository embedded in your main repository. In Git you can add a submodule to a repository. Git Submodules basic explanation Why submodules?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |