1

I have a repo (parent project) that relies on a submodule. I need to update the submodule to the latest commit but it is not working.

I created the submodule like this: git submodule add https://github.com/library.git (not the real name)

I tried to update it with this: git submodule update --remote --merge

It does not work. I still have the old code in the parent project. When I look at the code in the repo of the submodule the new code is there.

I updated the repo of the submodule, commit and push. That works. I update the submodule in the parent project, that does not work. I make a change to the parent project, commit and push. The submodule is still not updated.

I tried git submodule --init as suggested in one post. This is a terrible command. First, it copies all the code in the submodule to the parent project which is a waste, potential source for errors now with the same code in two locations plus its the exact same wrong (old) code.

If I issue this command: git submodule update --remote --merge, I get no response.

Anyone know how I can update the parent project to point to the latest submodule?

Jona
  • 1,218
  • 1
  • 10
  • 20
user14202986
  • 153
  • 1
  • 1
  • 9

2 Answers2

0

Well I found if I delete the submodule and then add it again I get the latest push. Not ideal, but at least it works and I can move forward.

git submodule deinit -f path
git rm -f path

Im not sure exactly what those commands do, but I followed a recommendation and it worked. Id still be interested in doing this a better way.

user14202986
  • 153
  • 1
  • 1
  • 9
0

git submodule update --remote should have updated the code of the submodule with the latest from, by default, master.

But if it des not work by default:

  1. Make sure you are using the latest Git 2.28 (if not, upgrade and check if the issue persists)
  2. Try and recreate the module, this time specifying which branch you want to track (git submodule add -b master <URL to Git repo>)
  3. If nothing work, try the script at the beginning of this answer, which will go into each module and pull.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250