Ignoring files and folders in Git

Create a global .gitignore

touch ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
  • foo/ will match a directory but not a file or symbolic link
  • foo without the / is a glob pattern
  • **/foo will match a file or directory anywhere

Remove files that are ignored now but are still in the Git repo

git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master