1

I am working in my branch and I needed an external submodule, so from the root of my project I did.

git submodule add https://github.com/blah/blah ./location/submodue
Cloning into ...
...
git commit -am "Added submodule"

This seems to have worked and I was able to carry on working on the main branch, while working I noticed a bug in the submodule, so I made the change directly in it.

But when I did a git add . no changes were found, the code changes I made were not found. There was nothing to commit but git did report git +0 ~1 -0!, but I was not able to add/commit that one change.

So I made the changes to the 'main' project, then I pulled the changes and everything was fine again.

So how can I make changes to the submodule and commit those changes from the 'main' branch that uses that submodule

(Let me know if you want the links/paths to the actual github projects).

FFMG
  • 1,208
  • 1
  • 10
  • 24

1 Answers1

1

So how can I make changes to the submodule and commit those changes from the 'main' branch that uses that submodule

You need to:

  • make sure your submodule has checked out a branch: by default, a submodule is always in a detached HEAD mode, checking out a SHA1, not a branch.

You can make each submodule follow a branch.
See "How to make an existing submodule track a branch".

cd /path/to/your/parent/repo/Foo
git config -f .gitmodules submodule.bar1.branch branch1
  • make a new commit (fix) in that branch, and push to the remote repo of that submodule (or a fork)
  • go back to the parent repo, add, commit and push in order to record the new SHA1 of that submodule. (that is: the gilink, a special entry in the index)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250