A .gitignore
file is a simple text file where you list files and folders that you want Git to ignore. Ignored files won’t be tracked, which keeps your repository clean and secure.
We don’t want to commit everything into our repository. Common things to ignore include:
node_modules
. These can contain thousands of files and should be installed by each developer, not stored in Git./dist
or /build
folder..env
..gitignore
(the dot at the beginning is important)..gitignore
FileThis is a common example for a web project:
Ignore Node.js dependency folder node_modules/
Ignore environment variables file .env
Ignore build output folder dist/
Ignore OS-specific files .DS_Store Thumbs.db
.gitignore
file at the very beginning of a new project, before you make your first commit.You don’t have to create these files from memory. You can use online tools to generate a comprehensive .gitignore
file for your specific project.
gitignore.io (Recommended): This is the best tool. Simply go to the site, type in the technologies you are using (like Node
, VSCode
, Windows
), and it will create the perfect file for you to copy and paste.
GitHub’s Template Repository: GitHub maintains its own repository of official .gitignore
templates. This is a great place to browse and find a specific file if you know what you’re looking for.