3

I have node_modules and bower_components in .gitignore. Every time I switch branches, all the dependencies get removed (with exception to the globally installed ones) and I have to reinstall all of them.

I'm currently using git stash save --keep-index --include-untracked —all, but I was wondering if there's a simpler solution where it would retain the the directories in .gitignore after switching back from another branch.

dmr07
  • 1,388
  • 2
  • 18
  • 37

1 Answers1

2

This issue had something to do with these directories being tracked in the git index prior to my recording them in .gitignore.

I did the following to resolve the issue:

  1. Remove <directory> from .gitignore
  2. git rm -r --cached <directory>
  3. Add back <directory> to .gitignore
  4. Stage and commit changes to

I got this from How to stop tracking and ignore changes to a file in Git?, and it solved my node_modules problem, but there's some residuals in bower_components that still remain tracked.

Community
  • 1
  • 1
dmr07
  • 1,388
  • 2
  • 18
  • 37
  • This doesn't work for me `fatal: pathspec 'node_modules/' did not match any files` please review https://stackoverflow.com/questions/52914838/git-moves-files-folders-with-when-checking-other-branches-although-i-use-stash-b – Imnotapotato Oct 21 '18 at 14:57