How GitIgnore and GitHub Repos Work |Video upload date:  · Duration: PT6M1S  · Language: EN

Learn how .gitignore controls which files enter a GitHub repository and how to untrack files that should be ignored

What .gitignore does and why you should care

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.

Quick rules that will save your repo and your dignity

  • Place a plain text file named .gitignore at the repository root
  • Use templates for common languages and frameworks to avoid reinventing the wheel
  • Use a leading slash to match from the repo root and a trailing slash to mean folder
  • Prefix a pattern with ! to unignore a file that would otherwise be ignored

Common entries you will actually want

Examples 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.

Fixing files that are already tracked

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

Global ignore for personal clutter

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

Patterns that actually matter

  • /build prevents tracking the build folder at repo root
  • logs/*.log ignores log files in the logs folder
  • *.secret ignores any file with that extension
  • !important.txt keeps a single file despite a broader rule

Staging behavior and final checklist

Staging 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.

  • Create or edit .gitignore at the repo root
  • Remove tracked files you now want ignored with git rm --cached
  • Commit and push the changes to keep the remote clean
  • Set a global ignore for OS and editor artifacts

Final thought

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.