'Exclude folder from git in Visual Studio Code
I am using Visual Studio Code version 0.7.10. I want to use version control. I figured this was a good time to start teaching myself to use git. I have never used it before.
How do I make git ignore my "node_modules" folder? Every item in this folder is listed for possible commits and that is cluttering up my workspace. I don't want to upload all the packages. I figure whoever runs the package.json can do that on their own computer.
Thought: I found under File > Preferences > User Settings that there is a configuration file called "settings.json" that will overwrite the default settings. I see a "Git configuration" in the default settings but I can't find any documentation on my possible options here. I would think I could do a "git.exclude" but where do I begin. This is only a guess at a solution. I am sure the real answer is something completely different.
I am looking for any documentation you could point me to. Thanks!
UPDATE: I made a change to the ".git/info/exclude" file and my Git repository view cleared up instantly. Here is a link that talks about the exclude file and why it worked for my VS Code editor. (https://help.github.com/articles/ignoring-files/)
Solution 1:[1]
You would make a .gitignore file in the base directory of your git repository and add any files or folders that you would like to ignore. In your case your file would contain
/node_modules/
Documentation: http://git-scm.com/docs/gitignore
Solution 2:[2]
You can use this setting:
"git.ignoredRepositories": []
which specifically does what you're asking. This won't pollute your .gitignore file if the only thing you want to do is to exclude a folder from vscode git but not from git itself. For example, this is useful if your home dir is under version control, since thousands of files would have to be ignored otherwise, which is hardly what you want.
Solution 3:[3]
Follow the steps to add a folder to .gitignore using UI
- Click Source Control on left pane
- Click on three dots at right top of Source Control tab
- Select View & Sort>View as Tree
- Right click on the folder you want to add to .gitignore
- Select Add to .gitignore
You are done!
Solution 4:[4]
This is an old solved question, but for anyone else who is still struggling with the accepted (and correct) answer, you literally need to add a file to your main (ie root) project folder called:
.gitignore
If you add helloworld.gitignore it won't work. Or whywontthiswork.gitignore, etc. It must be .gitignore.
Inside the file, type this text:
/node_modules
Assuming your placement of the .gitignore file is at the same relative path of the node_modules folder, anything in node_modules will be excluded from change tracking.
Solution 5:[5]
Github maintain a repository containing .gitignore files for a lot of languages.
Here is the one you need for Node...
Or you could generate one (very useful if you use different technologies in the same repository) using the web site: http://gitignore.io
Ps: Except if you've got really good reasons (exclude rules that you want to keep only for you), don't use .git/info/exclude to ignore files but prefer to use and commit the .gitignore file (to share it with all repository users).
Solution 6:[6]
There is a simple way to do this.
git rm <file-name>
git commit -m '<message>'
git push
for folders,
git rm -r <folder-name>/*
git commit -m '<message>'
git push
Solution 7:[7]
Create a file with .gitignore & put the folder or file name which one you want to ignore.
to ignore everything below node_modules folder
echo node_modules/ > .gitignore
Solution 8:[8]
Adding to the other answers pointing you to make a .gitignore file...
As a good starting point for any .gitignore file, you can search at https://gitignore.io. Specific settings for 'VisualStudioCode' and various other tools and languages can be entered, and the site will generate a .gitignore file for you.
Additional points
You can add a
.gitignoreto any folder to create entries specific to that folder and its nested folders as well.By default, Git will not save an empty folder. You can put an empty
.gitignorefile into a folder to force git to save it.
Solution 9:[9]
For those who want to exclude a file vie private ignore using .git/info/exclude. In my case VSCode still kept it as tracked and listed. Even git rm -f --cached <filename> didn't helped at all.
What helped instantly was the extension named GIT-EXCLUDE Just had to install it and as I had the file alredy in the exclude file it disappeared right in the moment when the extension started.
It also allows you to use RMB in VSCode file explorer to exclude files conveniently.
Solution 10:[10]
To exclude a folder from git across all projects on your machine, you can use core.excludesfile configuration Git documentation
Create a file called ~/.gitignore_global then add files or folders you would like to exclude like node_modules or editor folders like .vscode
Then run:
git config --global core.excludesfile ~/.gitignore_global
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TuringTux |
| Solution 2 | memeplex |
| Solution 3 | Kokul Jose |
| Solution 4 | |
| Solution 5 | |
| Solution 6 | Rahul |
| Solution 7 | reza.cse08 |
| Solution 8 | |
| Solution 9 | Hexodus |
| Solution 10 | Jeff Spicoli |
