Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule init does absolutely nothing

I have a strange problem with "git submodule init"

When I added the submodules using "git submodule add url location" it cloned the repository just fine and everything was ok.

When I pushed all my changes back to the parent repository, added the .gitmodules files, etc and cloned the repository back, I tried to initialise all the submodules using "git submodule init"

And nothing happens :( Literally nothing, no output, no extra files, it does not even attempt to do anything actually.

So I am wondering, what did I do wrong?

.gitmodules:

bash$ cat .gitmodules [submodule "projects/subprojectA"]     path = projects/subprojectA     url = ssh://[email protected]/test/projectA.git  [submodule "projects/subprojectB"]     path = projects/subprojectB     url = ssh://[email protected]/test/projectB.git 
like image 238
Christopher Thomas Avatar asked Sep 29 '16 08:09

Christopher Thomas


People also ask

How do I initialize a submodule in git?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

Why do people dislike git submodules?

You can't just clone the repo any more, you have to clone recursively. You can't just checkout branches any more, you have to init and update the submodules too, with extra complications if the same submodules don't exist in all branches. You can't just commit/push, you have to commit/push the submodules first.

Is using git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.


1 Answers

ok, I have figured out what I did wrong.

When I added the git submodules, I did a git status and it told me three things had changed

.gitmodules projects/subprojectA projects/subprojectB 

when I was pushing all my changes to the repository, I didnt want to commit the submodules, cause I thought it would add all the files I just cloned, so I just did a git add .gitmodules and committed and pushed that.

But this is wrong, you need to do a git commit and commit everything it tells you, then when you do this, git registers those paths and when you clone, it will work.

but if you do not commit those folders, it wont register them and wont clone them when you clone the parent repository.

so that was my mistake, I misunderstood that adding those directories would add all the submodules code to the parent repository, I tried to sidestep that and it stopped working.

so just add your submodules and commit the results, it will all work out just fine :D

Thanks for Protectators help, regardless!

like image 104
Christopher Thomas Avatar answered Sep 23 '22 12:09

Christopher Thomas