How to remove node_modules from github or bitbucket

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:

  1. Create a .gitignore file
  2. Remove the node_modules folder
  3. 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:

How to add an empty folder/directory in Git

Resolve- Refusing To Merge Unrelated Histories Git Error

Open Github Repository Directly In Vscode In Browser Online

How to change git username and password on PC

How to change image size in markdown in GitHub

How to save username, email and password globally in Github?

How to check Git email address and username in terminal?

Checkbox inside GitHub Markdown Table

Scroll to Top