Hello fellow students of Mosh
I am currently taking the Node course for a project I am working on for my university. I am trying to use .gitignore to exclude node_modules but it doesn’t seem to be working. First I thought that this might be due to the node_modules folder being under another folder. But even when I moved the .gitignore file to the same folder as the node_modules it’s still not working. Do you guys have any suggestions on how can I solve this?
what command you are using to exclude may I know
try this in bash:
touch .gitignore (creating file)
echo node_modules>>.gitignore (this ll add your file into git ignore))
note >> if you already add this file (node_modules) to staging area then this file ll not be ignored
My .gitignore file sits a the root of my project folder.
All that I have in it is:
node_modules/
coverage/
That works for me.
This is indeed important.
What does that exactly mean, the staging area?
I am not using any commands over terminal. I am working on the project over VSC and that is how I basically created the .gitignore file.
Creating .gitignore by VSC or from terminal is both okay.
As a test you could create a new project, add .gitignore file and than do the GIT commands. Still the same problem?
Git staging is an area where git allow to continue making changes to the working directory
When you do git add * (it means you add all your file to staging area) if you want to ignore some file it is necessary to add file into gitignore before running this command (git add *)
Well, before I do git add*, the .gitignore file is already set including the files to be excluded.
So it’s basically trying to add both files, .gitignore and node_modules, to the staging area at the same time. But I guess it is supposed exclude node_modules in this case right?
I didn’t get you let say
I have 2 file in a root folder (file1.py and file2.py) but I want to ignore file2 and commit
Here what I do
git init
touch .gitignore
echo file2.py > .gitignore
git add * (.gitignore and file1 ll be added)
git commit -am"initial commit"
Test
Lets edit file2
git status
(You ll see a message nothing to commit )