Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a folder to the .gitignore

Maybe my Googling skills are lacking but this seems like a question that should give me back thousands of hits and yet, I can't find a straight answer.

Simple as this:

I do constant pushes to github to share with a remote developer. We both have npm and bower installed. No need to push these huge folders to github all the time. My node_modules are ignored. But I can't seem to get gitignore to ignore my bower_components folder

I'm not too savvy on cmd, I barely scratch the surface so if you ar going to suggest that, please don't assume I know what you are talking about. Otherwise if it is as easy as adding it to the file itself using an IDE, well, I did that and no cigar. Here is my .gtignore file for your review

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-    task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages
bower_components

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

Am I missing anything? How do I make the bower_components ignored?

Thank you

like image 549
LOTUSMS Avatar asked Jul 30 '16 13:07

LOTUSMS


People also ask

Can you Gitignore a folder?

A . gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track. Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder.

How do I add folders to Git contents?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Where is Gitignore folder?

gitignore is located in the root directory of your repo. / will ignore directories with the name.


1 Answers

If you want to ignore folder, you need a trailing slash:

bower_components/

Then check if the rule apply with git check-ignore -v (the -v is important if you want to see the exact .gitignore file and line which causes a file to be ignored)

git check-ignore -v -- bower_components/afile

If that does not apply, then remove the content of that folder from the history of that repo:

git rm --cached -r -- bower_components/
git add .
git commit -m "Remove bower_components folder"

Then the .gitignore rule will take effect immediatly.

like image 55
VonC Avatar answered Oct 01 '22 05:10

VonC