How to remove node_modules from github or bitbucket
Step by step process to remove node_modules from github or bitbucket after the folder is added to the repository with the help of gitignore file.
In this post, we will see how to remove node_modules folder from our repo in Github and bitbucket.
If you have accidentally pushed your node_modules folder to a remote repository on git, then deleting it locally before your next push, will not delete the folder from the remote repo on Github.
So how can we remove it?
To remove it we have to follow these steps:
- Create a .gitignore file
- Remove the node_modules folder
- Commit all change to github or bitbucket
Let's follow each step in detail
1. Create a .gitignore file
First, check in your project's root folder if you have a .gitignore file.
If you don't, you have to create a .gitignore file in the root directory.
touch .gitignore
2. Remove the node_modules folder
Next, we have to add the node_modules folder in the .gitignore file.
Open the .gitignore file and add the following line in the file.
node_modules/
Now, remove/delete the node_modules folder from the project folder. To do that, run this command
git rm -r --cached node_modules
Or you can run this too
git rm -r --cached .
3. Commit all changes to git
Now, you can commit the local repository to git without the node_modules folder.
git add . git commit -m "remove node module folder"
Then push the code to your remote branch
git push origin master
Related Topic:
Related Posts
Fix 'failed to push some refs to' Git Errors
If you have encountered the "error: failed to push refs to" error in git, then follow this solution provided in this article to easily fix the error.
[Fixed] GitHub "fatal: remote origin already exists" error
Find out to fix "fatal: remote origin already exits" github error while working with remote git repository.
Solved "No such remote origin" Git Error Fatal
Short article on how do I fix remote origin already exists git error faced when trying to push to remote origin in Github and BitBucket.
Fix - "fatal:refusing to merge unrelated histories" git error
This article is about how to resolve or fix fatal:refusing to merge unrelated histories git error.
