Sato
Sato

Reputation: 8622

How do you develop along with a git submodule?

Here is my project structure

MainProject
|  README.md
|  src/
|  lib/      # this is a submodule

When I develop MainProject, I will also develop lib/, I mean MainProject/lib/.

When I do push, I will copy all changes in MainProject/lib/* into MainProject/../lib/, which is a separate git directory, then push.

After that I will do a submodule update in MainProject/lib/ to latest from remote.

Then I will commit and push changes in MainProject.

It suffers. How do you develop along with a git submodule?

ADD

I want all changes in lib/ pushed to remote lib repository. And all changes beside lib/ in MainProject pushed to remote MainProject.

So if I directly put to remote lib repository inside MainProject/lib And then add and commit and push changes beside lib/ in MainProject to remote.

If someone else clone MainProject and do submodule update, will he get the latest sources?

My .gitmodules:

 [submodule "lib"]
    path = lib
    url = [email protected]:XXX/YYY.git
    branch = master

Upvotes: 0

Views: 228

Answers (1)

VonC
VonC

Reputation: 1329472

You shouldn't have to copy your changes: you can push directly from MainProject/lib to the same upstream repo (the one in git remote origin) than the upstream repo (git remote origin) found in MainProject/../lib.

MainProject/lib is a nested repo in its own right: you can add commit and push them directly from it.

But then, you have to go back to MainProject/, add, commit and push in order to record the new gitlink (the special entry in the index of the parent repo which records the SHA1 of the submodule lib)


add and commit and push changes beside lib/ in MainProject to remote

No: when you commit anyhting in lib, that will change the gitlink (the 'lib' entry in MainProject index)

By "going back to MainProject" (meaning, you were in MainProject/lib and you do cd ..), you can do a git add ., which will:

  • add all your changes beside lib/
  • record the new SHA1 associated with lib/ submodule (the 'lib' gitlink entry)

But pushing the MainProject, complete with the updated gitlink 'lib' entry, you are making sure that anyone cloning your MainProject will get back lib at that exact updated SHA1.

Upvotes: 1

Related Questions