Even after adding the file to gitignore, it continues on github

Asked

Viewed 128 times

0

My situation is this: I created a project, I went up on github and after a long time, I realized that I went up the folder node_modules, and I don’t want her there. I created the .gitignore and add the folder there, but still, keep trackeando. I’ve done the classic:

git pull origin master
git rm -r folderName
git commit -m "rm folderName"
git push origin master

and it didn’t work. I also tried:

git rm -r --cached . 
git add .
git commit -m "rm ignored files"

but also without success. I just don’t delete file by file inside github because it would be unviable, and I wouldn’t want to start a new repository again because commits are for job interview logging.

1 answer

3

Since the node_modules directory is already being tracked as part of the repository, the rule .gitignore will not apply to him.

You need to clear the git directory using

git rm -r --cached node_modules
git commit -m "removing node_modules"

You can run the above 2 on git-bash.

After that, the rule . gitignore will ignore the directory.

Note that this will remove the node_modules directory from your other repositories as soon as you insert the changes. Only the original repository where you committed will still have the node_modules folder.

Do not forget that in . gitignore must be set node_modules/ to be ignored.

These controls shall be performed by a git client

https://www.it-swarm.dev/pt/git/.gitignore-nao-esta-ignorando-diretorios/1046576469/

  • 1

    It worked here, thank you very much! What I needed to do the most was switch to the master branch before, I forgot to mention this detail :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.