fatal: in unpopulated submodule
AngularjsGitGithubAngularjs Problem Overview
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.
Angularjs Solutions
Solution 1 - Angularjs
It seems like, you may have removed the .git
folder. In that case you can try
git rm --cached angulartest -f
Solution 2 - Angularjs
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.
Solution 3 - Angularjs
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
- Remove all
.git
folder inside the sub directory causing the error cd
to the main directorygit rm --cached sub_directory_name -f
git add --all
to add the subdirectory and contents, recursivelygit 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.
Solution 4 - Angularjs
Here's what I did
- Make a copy of the 'submodule' directory somewhere outside of the repository (e.g. your desktop)
- Delete the submodule directory from your repo
- Commit the repo
- Go into the copy you made of your submodule directory, delete
.gitignore
file and.git
directory - 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!
Solution 5 - Angularjs
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
Solution 6 - Angularjs
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.