About .gitignore generator
A .gitignore file tells Git which files not to track, such as build output, dependencies and secrets.
What to ignore
- Dependencies like node_modules and virtual environments.
- Build output and caches.
- Environment files with secrets, like .env.
- Operating system and editor files such as .DS_Store and .idea.
Already tracked files
Adding a file to .gitignore does not remove it from Git if it is already tracked. Run git rm --cached <file> to stop tracking it.
A worked example
For a Node.js project on a Mac, the file should ignore node_modules/, dist/, .env and .DS_Store. For Python you would add __pycache__/, .venv/ and *.pyc. Select your language and your operating system to get a combined file.
If a file is already tracked
- Run git rm --cached filename to stop tracking it without deleting it.
- Commit the change and the file will be ignored from then on.
- If a secret was committed, remove it and also change the secret, since it remains in the history.
