Think of .gitignore as the bouncer for your repository. It tells Git which files to ignore when you stage and commit. It will not rescue you if you already committed a secret key, but it will stop future disasters and reduce the number of angry code review comments about giant binaries.
.gitignore
at the repository root!
to unignore a file that would otherwise be ignoredExamples that belong in most projects include node_modules/
and .env
. Add OS and editor junk like .DS_Store
and Thumbs.db
to a global ignore file instead of cluttering the repo version of .gitignore.
If Git is already tracking a file you now want ignored adding it to .gitignore will not magically untrack it. You need to remove the tracked copy from the index while keeping your local file intact.
git rm --cached path/to/file
# or for a folder
git rm -r --cached node_modules
Then update and push the .gitignore file as usual
git add .gitignore
git commit -m "Update .gitignore"
git push
Some files are personal and not relevant to the team. Use a global ignore file to keep those out of every repo you touch. Configure it once on your machine and forget about it.
git config --global core.excludesfile ~/.gitignore_global
# then add patterns like
.DS_Store
Thumbs.db
/build
prevents tracking the build folder at repo rootlogs/*.log
ignores log files in the logs folder*.secret
ignores any file with that extension!important.txt
keeps a single file despite a broader ruleStaging is respectful. When you run git add
Git follows .gitignore rules and will not stage ignored files unless you forcibly add them. To wrap this up follow a short checklist.
.gitignore
at the repo rootgit rm --cached
Using .gitignore and the global excludes file is one of the easiest ways to keep your repository tidy and your teammates from muttering. It will not protect secrets that are already committed, so treat that as a separate emergency and rotate keys as needed. Otherwise enjoy a repo that does not contain your snack sized backups or editor temp files.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.