ignoring subdirectories using gitignore and ignore files in general - gitignore

Say I want to ignore node_modules, but also node_modules for subdirectories:
project/
node_modules
bar/
node_modules
foo/
node_modules
baz/
node_modules
.gitignore
what do I need to put in my .gitignore file too ignore all node_modules folders?

By default, git uses patterns from .gitignore to match content in sub-folders recursively. So, putting the following content into .gitignore is enough.
node_modules/
If your folder node_modules has been added into the repo already. You need to untrack them.
git rm --cached node_modules

Related

.gitignore in subdirectory is getting ignored

I have created a .gitignore file in a subdirectory.
/errors/company/.gitignore
I need it to ignore the file /errors/company/seiten/start/content.phtml.
Content of .gitignore:
seiten/start/content.phtml
But it does still show the file if execute git status. Why?
If you have already commited the .gitignore file, and you still see that file in git status, it is because the file was being tracked from before. You should do the following:
git rm --cached /errors/company/seiten/start/content.phtml
That should do the trick.
PD: I would leave just one .gitignore in the root directory with all the ignored paths and files.

Git commit shows changed files like metadata although they are in gitignore file

The information on the commits on GitHub says there are thousands of additions and deletions in files such as metadata even though the metadata is in the gitignore file.
This is how looks like my gitignore file:
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
.springBeans
You probably added certain files to .gitignore after they had already been tracked by git. If this is the case, you need to tell git to untrack the file:
git rm --cached <file>

Github ignore multiple node_modules

Im having two kind of node_modules in my folders.
One in the root folder, that works fine, but one also in the folder called "html/app" ( so would be html/app/node_modules )
Why wont it ignore it? it adds everything in the node_modules app folder when i do the command "git commit ".
Current .gitignore contains:
/dist
/tmp
/out-tsc
# dependencies
/node_modules
/html/app/node_modules
html/app/node_modules
If I understood your question right - you want to ignore both node_modules folders.
Try to cut that folder from project, then commit it and then return node_modules folder back.
Future commit's would ignore both folders.
EDIT: Probably it works in that way now because of that git already track that folder.

gitignore does not ignore .DS_Store files

why gitignore does not ignore .DS_Store files ?
this is my .gitignore file
#Directory based project format
.idea
# Ignore Mac DS_Store files
**/.DS_Store
#node modules for grunt
node_modules
#files generated with grunt
src/app.js
this works for node modules and src/app.js perfect, but does not ignore DS_Store.
Can anybody tell me why ?
Use this command to delete a file from the repo, but not delete the file itself:
git rm --cached <file>
After you removed it, you can ignore it using .gitignore.

How to ignore IDE settings on Git?

I have below Git information and I would like to ignore settings of my IDE (Eclipse).
modified: myproject/.classpath
modified: myproject/.project
modified: myproject/.settings/com.google.gdt.eclipse.core.prefs
modified: myproject/.settings/org.eclipse.core.resources.prefs
modified: myproject/.settings/org.eclipse.jdt.core.prefs
modified: myproject/.settings/org.eclipse.wst.common.component
modified: myproject/.settings/org.eclipse.wst.common.project.facet.core.xml
modified: myproject/.settings/org.eclipse.wst.validation.prefs
I tried the below statements in my .gitignore file, but it doesn't work for these settings:
.project
.classpath
.settings
*.project
*.classpath
*.settings
/.project
/.classpath
/.settings
.project/
.classpath/
.settings/
*.project/
*.classpath/
*.settings/
I am using Mac OS X and I also added global gitignore file with these settings git config --global core.excludesfile '~/.gitignore', but I'm still getting the above Git update messages when I check with git status. What am I wrong?
If those elements were already committed, you need to remove them first:
git rm --cached .project
git rm --cached .classpath
git rm --cached -r .settings
The --cached option allows them to stay in the working tree, while being recorded for deletion.
Once deleted, they will be ignored.
Once committed, the next changes will be ignored.
A simple .gitignore in myproject/ folder is enough:
.project
.classpath
.settings/
Note the / for .setting folder: that will ignore everything in it.
Following is my .gitignore config for a java web project:
*.class
*.swp
*.cache
*~
bin/**/*
target/**/*
build/**/*
gen/**/*
# tmp source folder
tmp/**/*
# js plugin
WebContent/js_plugin/lib/**/*
After git 1.8.2, If you want to ignore a folder named abc in any folder or subfolder, use following:
**/abc/**/*
So, I suggest you upgrade your git, if it's too old.
By the way, in my opinion, if team is using the same IDE, you should sync the .classpath things to git, ofcause, this is base on you have convention to name your jdk / tomcat / ... things like this. So that,once a jar is added via maven, all people get it after pull.
But, if you commit eclipse config, when push, make sure that change is useful, if not, don't commit, e.g. 2 source folder just change their line orders, in this case you can git checkout -- xxx, to ignore that change, so that won't effect other people.
It worked for me yeah but removing files from cache would be more helpful
#IDE files .gradle .idea idea-module-files *.iml com.springsource.sts.config.flow.prefs org.sonar.ide.eclipse.core.prefs
org.springframework.ide.eclipse.beans.core.prefs
org.springframework.ide.eclipse.core.prefs
.springBeans
eclipsebin
org.eclipse.jdt.core.prefs
org.eclipse.jdt.ui.prefs
NPM packages
**/node_modules
Compiled class file
*.class
Test classes
**/testclasses