Ways to ignore files locally without editing .gitignore

Ways to ignore files locally without editing .gitignore

I will introduce methods to ignore files only in your local environment without editing .gitignore. I compared three approaches: .git/info/exclude, global gitignore, and skip-worktree, and organized when to use each one.
2026.06.04

This page has been translated by machine translation. View original

Introduction

When working on team development, there are often situations where you want to exclude files that only you use from Git management.

  • Personal notes and TODO files
  • IDE workspace settings (.idea/, .vscode/settings.json, etc.)
  • Local-only docker-compose.override.yml
  • Debugging scripts and log files

Adding these files to .gitignore would affect every team member's repository. For the need to "ignore files only in my local environment," Git provides several methods.

This article organizes the following four methods through hands-on practice.

Method Scope Target Impact on Team
.gitignore Entire repository Untracked files Yes (subject to commit)
.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 to all)

Check 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 is never pushed to the remote.

How to use

Open .git/info/exclude with any editor and add the patterns you want to ignore.

# Open with editor
vim .git/info/exclude

Write it as follows.

# 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, it is working correctly.

Key points

  • Since the .git/ directory itself is outside Git's management, it has absolutely no impact on team members
  • Configuration is required per repository
  • Like .gitignore, it is only effective for 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). Since configuring this per repository every time is tedious, 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 check whether the configuration is reflected:

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 flexible (~/.config/git/ignore is also commonly used)

Method 3: git update-index --skip-worktree (For tracked files)

The two methods above only work for files not yet tracked by Git.

So what do you do if you want to modify a file locally that is already committed to the repository (e.g., config/database.yml or .env.example), but do not want to commit those changes?

The skip-worktree flag

# Make Git ignore local changes to the file
git update-index --skip-worktree path/to/file.txt

Once this flag is set, Git ignores changes to that file in the working tree. It will also no longer appear in git status.

How to unset

# Return the file to Git tracking
git update-index --no-skip-worktree path/to/file.txt

Checking the current configuration

You can list which files have the skip-worktree flag set.

git ls-files -v | grep '^S'

Lines starting 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
Original purpose Intentionally ignore local changes Performance optimization (for large repositories)
How Git treats it Ignores working tree changes 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

# Change local DB connection settings, but don't want to commit them
git update-index --skip-worktree config/database.yml

# Edit the file
vim config/database.yml

# Not shown 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 at top).

  1. Command-line patterns--exclude option of git ls-files, etc.
  2. .gitignore (inside directory) — Applies to that directory and subdirectories
  3. .git/info/exclude — Repository-local exclude
  4. 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 tracked files 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 your own development environment without polluting .gitignore. In particular, understanding the difference between skip-worktree and assume-unchanged can help you avoid unexpected issues.

References

Share this article