
Ways to ignore files locally without editing .gitignore
This page has been translated by machine translation. View original
Introduction
When doing team development, there are often situations where you want to exclude files you use personally from Git's management.
- Personal notes and TODO files
- IDE workspace settings (
.idea/,.vscode/settings.json, etc.) - Local-only
docker-compose.override.yml - Debug scripts and log files
Adding these files to .gitignore affects the entire team's repository. For the need to "ignore files only in my local environment," Git provides multiple approaches.
This article organizes the following four methods while trying each one in practice.
| Method | Scope | Target | Impact on Team |
|---|---|---|---|
.gitignore |
Entire repository | Untracked files | Yes (committed) |
.git/info/exclude |
Local only (single repository) | Untracked files | None |
| Global gitignore | Local only (all repositories) | Untracked files | None |
skip-worktree |
Local only (single repository) | Tracked files | None |
Prerequisites
- Git 2.x or later
- macOS / Linux / Windows (commands are common across all)
Check your version:
git --version
Method 1: .git/info/exclude (for a single repository)
Every Git repository has a file called .git/info/exclude. This file works with exactly the same syntax as .gitignore, but because it lives inside the .git/ directory, it will never be pushed to a remote.
How to use it
Open .git/info/exclude in any editor and add the patterns you want to ignore.
# Open in editor
vim .git/info/exclude
Write entries like the following.
# Personal notes
todo.txt
scratch/
# Local log output
logs/
# IDE-specific settings
.vscode/settings.json
Since it uses the same syntax as .gitignore, wildcards (*, **) and negation (!) are also supported.
How to verify
# Create todo.txt and check
touch todo.txt
git status
If todo.txt does not appear under Untracked files, you're done.
Key points
- Because the
.git/directory itself is outside of Git's management, it has absolutely no impact on team members - Configuration is required per repository
- Like
.gitignore, it only works on files not yet tracked by Git
Method 2: Global gitignore (for all repositories)
There are files you want to ignore in every project, such as .DS_Store (macOS), Thumbs.db (Windows), and *.swp (Vim). Configuring this per repository every time is tedious, so you can set up a global ignore file.
Setup steps
# 1. Create a global gitignore file
touch ~/.gitignore_global
# 2. Register it with Git
git config --global core.excludesfile ~/.gitignore_global
Common configuration examples
# ~/.gitignore_global
# macOS
.DS_Store
.AppleDouble
.LSOverride
# Windows
Thumbs.db
Desktop.ini
# Editors / IDEs
*.swp
*.swo
*~
.idea/
.vscode/
# Logs and temporary files
*.log
*.tmp
How to verify
To confirm the setting has taken effect:
git config --global core.excludesfile
# Output: /Users/<username>/.gitignore_global
Key points
- Applies to all Git repositories on the machine
- Ideal for OS-specific files and editor temporary files
- The filename and location are up to you (
~/.config/git/ignoreis also commonly used)
Method 3: git update-index --skip-worktree (for tracked files)
The two methods so far only work on files not yet tracked by Git.
So what do you do when you want to modify a file locally that is already committed to the repository (e.g., config/database.yml or .env.example), but you don't want to commit those changes?
The skip-worktree flag
# Tell Git to ignore local changes to a file
git update-index --skip-worktree path/to/file.txt
Once this flag is set, Git will ignore changes to that file in the working tree. It will no longer appear in git status either.
How to unset it
# Return the file to Git's tracking
git update-index --no-skip-worktree path/to/file.txt
Checking the current settings
You can list all files that have the skip-worktree flag set.
git ls-files -v | grep '^S'
Lines beginning with S are files with skip-worktree set.
Difference from assume-unchanged
There is a similar command, git update-index --assume-unchanged, but it serves a different purpose.
| Item | --skip-worktree |
--assume-unchanged |
|---|---|---|
| Intended use | Intentionally ignore local changes | Performance optimization (for large repositories) |
| How Git treats it | Ignores changes in the working tree | Assumes the file has not changed |
Behavior on git reset |
Flag is preserved | Git may remove the flag |
| Safety | Safe, as it is intended to be used deliberately | Git may override it as needed |
Conclusion: Use --skip-worktree when you want to ignore local changes. --assume-unchanged is merely a performance hint and may be automatically unset by Git.
Practical usage example
# Modify local DB connection settings without committing them
git update-index --skip-worktree config/database.yml
# Edit the file
vim config/database.yml
# Does not appear in git status
git status
# → nothing to commit, working tree clean
Git ignore priority order
Git reads ignore rules from multiple locations. The priority order is as follows (highest priority first).
- Command-line patterns — the
--excludeoption in commands likegit ls-files .gitignore(within a directory) — applies to that directory and its subdirectories.git/info/exclude— repository-local excludes- File specified by
core.excludesfile— global gitignore
When multiple rules match the same file, the last matching pattern takes precedence. Also, rules in a .gitignore at a deeper path take precedence over rules in a .gitignore at a shallower path.
Summary
| What you want to do | Method to use |
|---|---|
| Ignore untracked files in this repository only | .git/info/exclude |
| Ignore common files across all repositories | Global gitignore |
| Ignore local changes to a tracked file | git update-index --skip-worktree |
| Have the entire team ignore the same files | .gitignore (as usual) |
By making use of local-only ignore settings, you can set up a personal development environment without polluting .gitignore. In particular, knowing the difference between skip-worktree and assume-unchanged can help you avoid unexpected problems.