0

I'll start off by asking not to be judged for my use of git... It might not be optimal but it has worked so far. At the moment I am using it to sync all of my university projects between my devices. For some courses I also have submodules, as those are projects I am collaborating on with other people. So far using git submodules seemed to work fine and dandy, but for the last two submodules I have added I can push changes no problem but when pulling, the directory containing the submodule is completely empty, not even the .git file. Here are some things that I have tried and their results:

PS D:\University> git pull --recurse-submodules
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 5), reused 8 (delta 3), pack-reused 0
Unpacking objects: 100% (10/10), 1.04 KiB | 1024 bytes/s, done.
From https://github.com/**********/University
   0e65e10f..c47ea81b  master     -> origin/master
Fetching submodule Semantics and Rewriting/PokeBattles_project
Fetching submodule Year 2/New Devices Lab/smart-closet
Fetching submodule Year 2/New Devices Lab/smart-shop/final project
From https://github.com/**********/Smart-Shop-Project
   ab09d5a..3304c39  master     -> origin/master
 * [new branch]      dependabot/npm_and_yarn/mongoose-7.0.4 -> origin/dependabot/npm_and_yarn/mongoose-7.0.4
 * [new branch]      dependabot/npm_and_yarn/nodemon-2.0.22 -> origin/dependabot/npm_and_yarn/nodemon-2.0.22
warning: unable to rmdir 'Semantics and Rewriting/PokeBattles_project': Directory not empty
Updating 0e65e10f..c47ea81b
Fast-forward
 .gitmodules                                                        | 7 +++++--
 Human-Computer Interaction/Project/HCI-Project                     | 1 +
 .../{PokeBattles_project => PokeBattle-Project}                    | 0
 3 files changed, 6 insertions(+), 2 deletions(-)
 create mode 160000 Human-Computer Interaction/Project/HCI-Project
 rename Semantics and Rewriting/{PokeBattles_project => PokeBattle-Project} (100%)

PS D:\University> git submodule update --remote
Submodule path 'Year 2/New Devices Lab/smart-shop/final project': checked out '3304c398f204debcafa8e37dd89e038feeb345d2'

PS D:\University> git submodule update --recursive --checkout --remote

PS D:\University> git submodule foreach git pull origin main
Entering 'Year 2/New Devices Lab/smart-closet'
fatal: couldn't find remote ref main
fatal: run_command returned non-zero status for Year 2/New Devices Lab/smart-closet
.

As you can see, I have tried multiple methods that I have seen floating around. The two submodules in question are "HCI-Project" and "Pokebattle-Project". The HCI project contains a full Unity project besides a readme and a .gitignore, and the other one is just a readme. Ass you can see here, they are completely empty, not even a .git file. And because of that very reason git doesn't even seem to try pulling from those repos if I try git pull --recurse-submodules again:

PS D:\University> git pull --recurse-submodules
Fetching submodule Year 2/New Devices Lab/smart-closet
Fetching submodule Year 2/New Devices Lab/smart-shop/final project
Fetching submodule Year 2/New Devices Lab/smart-shop/login system
Fetching submodule Year 2/New Devices Lab/smart-shop/mongo_db-app
Already up to date.
Submodule path 'Year 2/New Devices Lab/smart-shop/final project': checked out 'eda28e13dc7cadeef8539fe0b2e3d6a2fe28cd0b'

PS D:\University> cd '.\Human-Computer Interaction\Project\HCI-Project\'
PS D:\University\Human-Computer Interaction\Project\HCI-Project> ls
PS D:\University\Human-Computer Interaction\Project\HCI-Project> cd '..\..\..\Semantics and Rewriting\PokeBattle-Project\'
PS D:\University\Semantics and Rewriting\PokeBattle-Project> ls
PS D:\University\Semantics and Rewriting\PokeBattle-Project> cd ../../
PS D:\University> cat .gitmodules
[submodule "smart-closet"]
        path = smart-closet
        url = ../smart-closet/
[submodule "Year 2/New Devices Lab/smart-closet"]
        path = Year 2/New Devices Lab/smart-closet
        url = ../smart-closet
[submodule "Year 2/New Devices Lab/smart-shop/final project"]
        path = Year 2/New Devices Lab/smart-shop/final project
        url = ../Smart-Shop-Project
[submodule "Year 2/New Devices Lab/smart-shop/login system"]
        path = Year 2/New Devices Lab/smart-shop/login system
        url = ../Basic-Node.js-Login-System/
[submodule "Year 2/New Devices Lab/smart-shop/mongo_db-app"]
        path = Year 2/New Devices Lab/smart-shop/mongo_db-app
        url = ../Mybrary/
[submodule "Semantics and Rewriting/PokeBattle-Project"]
        path = Semantics and Rewriting/PokeBattle-Project
        url = https://github.com/DragosSpiridon/PokeBattle-Project.git
[submodule "Human-Computer Interaction/Project/HCI-Project"]
        path = Human-Computer Interaction/Project/HCI-Project
        url = https://github.com/DragosSpiridon/HCI-Project.git

As you can also see, the submodules are defined in the .gitmodules file. Any idea of what is happening and how I can fix it?

1

1 Answer 1

1

The link provided by Peter Krebs contained the answer I needed. To be more specific, I had to use git submodule update --init --recursive. I did not know that a submodule also has to get initialized when cloning.

Note: the command only pulled the first commit (I think) and afterwards I also had to do another git pull origin main in the submodule directory.

Not the answer you're looking for? Browse other questions tagged or ask your own question.