14

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

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140

1 Answers1

39

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your response. The first set of instructions returned no errors. and the check ignore did identify that line 32 contained an ignore rule for bower but on commit, the bower folder remained in github. So I assume that your last set of instructions are for removing that from github but it returned an error where pathspec "rr" did not match any files. Am I supposed to replace rr for bower_components – LOTUSMS Jul 30 '16 at 13:44
  • @LOTUSMS Sorry, it was a type: `-r` (for `--recursive`), *before* the `--` – VonC Jul 30 '16 at 13:47
  • @LOTUSMS And that last set of instruction of for removing that folder from the index, locally. Not from GitHub. You would need to push your branch to GitHub for GitHub to reflect your local repo history. – VonC Jul 30 '16 at 13:48
  • lol. I figured, after I checked out the link someone commented above. But your question did help me. Thank you very much. Hopefully this question/answer gets a lot of visibility. It's basically the only straight answer in the internet so far – LOTUSMS Jul 30 '16 at 13:48
  • Right. That's what I meant. I did a commit and it is all great now! – LOTUSMS Jul 30 '16 at 13:49
  • how's -v important? it is just the reporting level – A_P Apr 21 '20 at 13:55
  • @A_P That I prefer always using `-v`, because it reports the actual `.gitignore` path and the line within that `.gitignore`, when a file is ignored. Without `-v`, it just prints the file if it is ignored, but you don't know what `.gitignore` directive is actually involved. – VonC Apr 21 '20 at 14:27
  • @VonC exactly my point. But your answer makes it look as if it will not work without -v. – A_P Apr 21 '20 at 15:06
  • 1
    @A_P It won't be useful without. I will edit the answer. – VonC Apr 21 '20 at 16:29
  • @Vonc what does the double dash '--' do? (git rm --cached -r -- bower_components/) – Y Bai Jun 07 '22 at 15:49
  • Thanks. I got it from git rm --help -- This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options). – Y Bai Jun 07 '22 at 15:51
  • @YBai Sorry for the late answer. I documented the double hyphen syntax back in 2009: https://stackoverflow.com/a/1192194/6309 – VonC Jun 07 '22 at 20:18