AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Git submodule detached head8/17/2023 You can read in depth about git submodules here. The submodule has a detached head because a submodule means 'check out a specific commit from the submodules repository'. Just by adding a set of repos as submodules, you can work around it nicely. So, I found this approach, which you can maybe think about 'simulating a monorepo'. We could reach a similar thing if working with monorepos, but this wasn't an option at the place I was working at the moment I wrote this post. Here is another approach to work with many repositories at once. My setup was a bit more complex, so I added the -recursive flag to bring all dependencies up to date. Adding a Submodule In our sample project, we create a new 'lib' folder to host this (and future) library code. Lets see how to work with Submodules in practice. from inside it like with any other repository. I.E not all submodules might be in the same branch, etc. This is because Gitâs garbage collector will clean up detached commits automatically, so you donât ever want to lose track of them. 3 Answers Sorted by: 72 I just ran into this same class of problem, and I was able to use the solution offered by AugustinAmenabar in the comments section of the accepted answer. A Submodule remains a fully functional Git repository: you can modify files, commit, pull, push, etc. Just keep that in mind when running git submodule foreach commands from the top level repo. So you can work from there as you usually do. This way we ensure it doesn't exit as an error, by reducing chances for failling of the pull.įor any other case, you can always cd into each submodule and see it still is a normal repository. This is useful because when running commands with the git submodule foreach command expression, if the command exits with an error code, it might cancel the whole foreach chain. Dont forget to add a correct pushurl for the you are working on or you will not be able to commit.This means that the checked-out commit - which is the one that the super-project (core) needs - is not associated with a local branch name. And all of that automatically, so you don't need to commit or stash your changes manually. By default your submodule repository is in a state called detached HEAD. This way, -autostash will assure to add your changes to stash, pull, then rebase on your branch and pop changes out of stash. Note: Execute git submodule init in the main repository directory. Git submodule foreach git pull -rebase -autostash origin branch_name Run it by using the syntax below: git submodule init - path1 path2.
0 Comments
Read More
Leave a Reply. |