Keep junk files out of your repo using .gitignore and clean untracked clutter.

  1. Create a .gitignore
  • echo “node_modules/” >> .gitignore
  • echo “*.log” >> .gitignore
  • git rm -r —cached .
  • git add .gitignore && git commit -m “Add .gitignore”
  1. Global ignores
  • git config —global core.excludesFile ~/.gitignore_global
  • echo ”.DS_Store” >> ~/.gitignore_global
  1. Cleaning untracked files (dry-run first!)
  • git clean -nd # preview files to be removed
  • git clean -fd # remove untracked files and dirs

Checklist

  • Project .gitignore configured
  • Global ignores for OS/editor files
  • You can preview and run git clean safely