How do I manage conflicts with git submodules?
I have not seen that exact error before. But I have a guess about the trouble you are encountering. It looks like because the master
and one.one
branches of supery
contain different refs for the subby
submodule, when you merge changes from master
git does not know which ref - v1.0
or v1.1
- should be kept and tracked by the one.one
branch of supery
.
If that is the case, then you need to select the ref that you want and commit that change to resolve the conflict. Which is exactly what you are doing with the reset command.
This is a tricky aspect of tracking different versions of a submodule in different branches of your project. But the submodule ref is just like any other component of your project. If the two different branches continue to track the same respective submodule refs after successive merges, then git should be able to work out the pattern without raising merge conflicts in future merges. On the other hand you if switch submodule refs frequently you may have to put up with a lot of conflict resolving.
I struggled a bit with the answers on this question and didn't have much luck with the answers in a similar SO post either. So this is what worked for me - bearing in mind that in my case, the submodule was maintained by a different team, so the conflict came from different submodule versions in master and my local branch of the project I was working on:
- Run
git status
- make a note of the submodule folder with conflicts Reset the submodule to the version that was last committed in the current branch:
git reset HEAD path/to/submodule
At this point, you have a conflict-free version of your submodule which you can now update to the latest version in the submodule's repository:
cd path/to/submodule git submodule foreach git pull origin SUBMODULE-BRANCH-NAME
And now you can
commit
that and get back to work.
Well, its not technically managing conflicts with submodules (ie: keep this but not that), but I found a way to continue working...and all I had to do was pay attention to my git status
output and reset the submodules:
git reset HEAD subby
git commit
That would reset the submodule to the pre-pull commit. Which in this case is exactly what I wanted. And in other cases where I need the changes applied to the submodule, I'll handle those with the standard submodule workflows (checkout master, pull down the desired tag, etc).