fatal: in unpopulated submodule

Viewed 62067

I am quite new to github and I am trying to find a solution to a current problem that I am having. I will go through my process step by step:

First I created a new folder named [project name] Next I used these commands:

    cd [project name]
    git clone [remote project from github url]

So far I have created a folder and cloned a project that my group is working on in github.

Next, I went inside that folder and created an angular project with

    ng new [angulartest]

This will create all the components of my angular test into the same folder that is the clone of the one from github.

Finally, I pushed the new angular test on github with

    git add [angulartest]
    git commit
    git push

What happens is that it only pushes the folder [angulartest] but none of its contents (even though there are contents in it). When I try to pull from its contents, I still just get an empty folder in return.

When I try to enter that folder and add each element of the contents, using these steps:

    cd [angulartest]
    git add e2e, src, nodemodules, etc
    git commit
    git push

It gives me the following error (even when I try to add each element individually):

fatal: in unpopulated submodule [angulartest]

I was wondering if it was a problem with my git syntax, the angular project, or the way I tried to clone the project. That way, I know which direction I want to be headed when looking for a solution.

6 Answers
git rm --cached . -rf

Stealing from anlijudavid's comment which was the actual answer for me on macOS with zsh. Adding -r based on Richard Collette's comment to this answer.

The root cause of this error in my case was that I have a subdirectory with its own .git folder inside. When I issued the git add --all command, I got this same error

Here's how I resolved the issue

  1. Remove all .git folder inside the sub directory causing the error
  2. cd to the main directory
  3. git rm --cached sub_directory_name -f
  4. git add --all to add the subdirectory and contents, recursively
  5. git status to verify that the items are added

I almost got a headache with this error but thanks for the previous answers, a combination of those worked for me.

Here's what I did

  1. Make a copy of the 'submodule' directory somewhere outside of the repository (e.g. your desktop)
  2. Delete the submodule directory from your repo
  3. Commit the repo
  4. Go into the copy you made of your submodule directory, delete .gitignore file and .git directory
  5. Copy the submodule directory back into your repo and commit

This meant I lost the commit history of the submodule but at least it fixed the issue of my files in the submodule not going to git!

If we cloned from third party repository we got this " fatal: in unpopulated submodule 'submodule name' " error.

This error fix for me using

git rm --cached <submodule name> -f

Also you can remove .git folder manually then you can try to git add

I got the same error when I had a subdirectory in my local repo, had deleted the .git to solve different issue, and then tried to add an updated html file to my repo. I went to github and uploaded the file using their GUI. Now I can see that everyhting matches and git status shows no issues.

Related