Search code examples
gitgithubgitignorenode-modules

Node.js modules pushed to GitHub


I am trying to push my project to GitHub and Heroku. Since I am using Node.js in my app, I have folder node_modules. Before I commit I have created a file called .gitignore to ignore the Node.js modules.

Inside the file I have added folder node_modules and tried to push to the GitHub repository from the comandline/Terminal. I was not expecting the Node.js modules to be pushed, but they appeared finally in the repository. Is there an ways I have to follow?

Here is how I resolve my issue

 - $ git rm -r --cached node_modules

Add folder node_modules/ to your .gitignore file:

 - $ git commit -m "remove the ignored directory node_modules"

And then

 - $ git push origin master

After that, if you refresh the GitHub page you will see the node_modules folder gone.


Solution

  • The node_modules folder should be added to the .gitignore file.

    First, get rid of your node_modules:

    $ git rm -r --cached node_modules  
    $ git commit -m "remove node_modules"
    

    Then, push your change

    $ git push origin master
    

    Refresh the page to see the desired effect.