Getting error while removing node_modules in git, vscode terminal
 git rm -r --cached node_modules
Error:
I faced the same issue. Do the below steps -
Run below commands in your terminal
git rm -r --cached node_modules
git commit -am "node_modules be gone!"
git push origin master
That's all!
You are good to go!
git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push
The error means node_modules directory is not under git version control. There are 2 possibilities:
They are not added to Git yet. Try running git status command, to see whether they appear as untracked files.
It has already been added into your gitignore file. To list all ignored files, try this command: git ls-files --others -i --exclude-standard
Create .gitignore file and add node_modules there:
touch .gitignore && echo "node_modules" >> .gitignore
Remove cached data:
git rm -r --cached .
Update your last commit:
git add .
git commit --amend --no-edit
git push --force-with-lease
You can remove folders from git without the command-line using vs-code.
If you want to remove node_modules from git:
node_modules to node_modulesxnode_modulesx to .gitignore (create a .gitignore file if you need to)The above 3 steps will remove the node_modules folder from git.
node_modulesx back to node_modulesnode_modules to .gitignore (or change node_modulesx to node_modules in your .gitignore)Now your node_modules folder still exists, but will not be committed to git anymore.
Make .gitignore file in your project directory.
.gitignore file will look like this 
/Folder_name
Type in below commands in the terminal or equivalent:
git rm -r --cached Folder_name (remove the directory from git but not delete it from the filesystem/locally)
git commit -m "remove unused directory"
git push origin <your-git-branch> (can be master or develop or others)