6/30/2023 0 Comments Git submodule set branch![]() ![]() arguments are given, only those paths are affected. This can, for example, be useful to remove all build products. Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. Git-clean - Remove untracked files from the working tree Synopsis git clean …Ĭleans the working tree by recursively removing files that are not under version control, starting from the current directory. ![]() $ git add -A # or just the unstaged submoduleĪlthough there are some more cases you can get your submodules into DETACHED HEAD state, I hope that you understand now a bit more how to debug your particular case. # which should open for you commit message from DETACHED HEAD $ git status # since your modifications are staged just remove untracked junk files # if you get 'error: could not apply.' run mergetool and fix conflicts $ git cherry-pick # hash which git showed you related to DETACHED HEAD However I personally would use just git cherry-pick in this case. The recommended option to create a temporary branch can be good, and then you can just merge these branches etc. If you want to keep it by creating a new branch, this may be a good time to do so with: Warning: you are leaving 1 commit behind, not connected to any of your branches: # to track so you don't see it anymore as untracked.īut if you managed to make some changes locally already for submodule and commited, pushed these to remote then when you executed 'git checkout ', Git notifies you: $ git checkout # you told already parent repo which is the submodules commit hash # which will fix the states for both submodule and parent since # since you did not push you submodule chage commit to remote. # from remote master which is 1 commit behind your local branch # since at this point you just asked git to update your submodule # as you see you are DETACHED and you are lucky if you found out now $ git status # will show again that (submodule has new commits) Submodule path 'path/to/submodule': checked out 'commit-hash' Nothing to commit, working directory clean # As normally you would commit new commit hash to your parent repo Modified: path/to/submodule (new commits) $ git commit -m"Your modification" # Let's say you forgot to push it to remote. update = checkout $ cd # and make modification to your submodule In the common cases, you already have fixed by now your DETACHED HEAD since it was related to one of the configuration issues above.įixing DETACHED HEAD when. # is here path releative to parent repo root First you want to make sure that your submodule has the branch checked out which you want to be tracked.If you haven't added your existing submodule like this you can easily fix that:.you tell git to update your submodule from remote.you tell git to perform rebase or merge instead of checkout.First you tell git to track your remote.Solution: Make your submodule track its remote branch by adding new submodules with the following two commands. ![]() Cause: Your parent repo is not configured to track submodules branch.# If no is specified, then it defaults to the current branch. # if the master branch already exists locally: Solution: Make sure your submodule is tracking the correct branch Cause: Your submodule is not tracking correct branch (default master).I believe that I am correct in stating, that we all have been there at some point where our submodule's HEAD gets detached. This is a common case when one does not use submodules too often or has just started with submodules. So back to the question: Why does it happen?Īfter pulling changes from server, many times my submodule head gets detached from master branch. Personally I hate answers here which direct to external links which may stop working over time and check my answer here (Unless question is duplicate) - directing to question which does cover subject between the lines of other subject, but overall equals: "I'm not answering, read the documentation." Submodule.update is what you want to change, see the docs - default checkout submodule.branch specify remote branch to be tracked - default master ![]()
0 Comments
Leave a Reply. |