Ignoring Files
Not all files should be tracked by Git. Compiled files, temporary files, environment-specific configurations, and sensitive data should be ignored. Git uses a special file called
.gitignore for this purpose.What Is .gitignore?
A
.gitignore file contains a list of patterns that Git should ignore. Once a file is ignored, Git will not track it, and it won’t appear in git status as untracked.Creating .gitignore
Create the file in the root of your repository:
touch .gitignoreThen open it in a text editor and add patterns.Common Patterns
*.log– ignore all .log filesbuild/– ignore the entire build foldersecret.env– ignore a specific file*.swp– ignore vim swap filesnode_modules/– ignore dependencies.DS_Store– ignore macOS system file
Example .gitignore
# Compiled output
dist/
build/
*.class
# Dependencies
node_modules/
# Environment
.env
.env.local
# OS files
.DS_Store
Thumbs.dbChecking What’s Ignored
To see which files are ignored, use:
git status --ignoredGlobal .gitignore
You can set a global ignore file for all repositories on your machine:
git config --global core.excludesfile ~/.gitignore_globalThis is useful for OS‑specific files like .DS_Store.Two Minute Drill
.gitignoretells Git which files to ignore.- Patterns can match filenames, folders, or extensions using wildcards (
*). - Add
.gitignoreto your repository so others share the same ignore rules. - Use
git status --ignoredto see ignored files. - Create a global ignore file for OS‑specific files.
Need more clarification?
Drop us an email at career@quipoinfotech.com
