![]() ![]() However, they can often be difficult to manage. Git submodules are useful as they allow you to use another project from within the project you are working on. This can become further complicated when switching branches as you will need to force checkouts which can often lead to missing files in subdirectories or submodules. You first need to unstage the original directory and then add the submodule. For example, if you delete a subdirectory and then add a submodule with the same name then Git will not let you. If you have been tracking files in your project and want to move them into a submodule, then this can create issues with Git. Switching from subdirectory to submodules You will then have to remove that directory and will need to run git submodule update –init to repopulate it when switching back to the branch. For example, if you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you will still have that submodule as an untracked directory. Prior to Git version 2.13, switching branches in a repository containing submodules can be quite difficult. This is complicated by two common operations: Switching branches Issues with submodules īecause of their complexity, using submodules is often difficult when working within a git repository. If this happens, you can go back into the directory and check out your branch again and merge or rebase origin/stable (or whatever remote branch you want), manually. If you forget the -merge or -rebase flags, Git will just update the submodule to whatever is on the server and reset your project to a detached HEAD state. To get around this you need to add a branch to the submodule to work on. This can make working on the submodule difficult and tricky to manage as any new commits added to the submodule will often be lost when updating it in the future. ![]() Adding a branch to a submoduleĪ Git submodule works on a “no branch” approach, which means that each submodule uses a specific commit rather than tracking a specific branch. git/config file to change the URL of the submodule from which to fetch updates when performing the git submodule update –remote command. After performing the git submodule init command you can edit the. git/config file which contains the remote URL of each submodule to update from. ![]() This is because the git submodule init command creates a. Changing the remote URL for a submoduleĪn alternative use for this command is to change the remote repository URL for a submodule. This would mean that when you perform the git submodule update –remote command, it will only fetch remote changes for the sub1 and sub2 repositories. You may only want to retrieve updates for sub1 and sub2 as you want sub3 to remain stable. In this case you can take advantage of the git submodule init command to specify which submodules you want to update when performing the git submodule update –remote command.įor example, you have a repository that has three submodules: sub1, sub2 and sub3. In some cases you may want to add several submodules to your repository but only want to track the changes made in a few of them. Tracking submodule changes Tracking changes of certain submodules Entering git add submodule branch into the AI command search will prompt a git submodule add command that can then be quickly inserted into your shell by doing CMD+ENTER. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |