# How to Ignore Temporary Files Globally in Git Using github/gitignore Templates

> Learn to globally ignore temporary files in Git by configuring core.excludesfile with github/gitignore templates. Automate exclusions for all your projects effortlessly.

- Repository: [GitHub/gitignore](https://github.com/github/gitignore)
- Tags: how-to-guide
- Published: 2026-02-24

---

**Configure Git's `core.excludesfile` to point to a global ignore file containing patterns from the github/gitignore repository's `Global/` directory to automatically exclude temporary files from every repository.**

Managing temporary files in Git traditionally requires adding patterns to each project's `.gitignore` file. However, Git provides a **global ignore mechanism** through the `core.excludesfile` configuration that applies patterns across all repositories on your system. By leveraging the battle-tested templates in the **github/gitignore** repository's `Global/` directory, you can efficiently **ignore temporary files globally** without polluting individual project configurations.

## Understanding Git's Global Ignore Mechanism

Git evaluates ignore patterns in a specific cascade: first the repository's `.gitignore`, then the global excludes file specified by `core.excludesfile`, and finally system-wide configurations. According to the github/gitignore source code in [`README.md`](https://github.com/github/gitignore/blob/main/README.md), placing temporary file patterns in your global excludes file ensures they apply universally while keeping project-specific `.gitignore` files focused on project dependencies.

The `Global/` directory follows a single-responsibility design, with each template targeting a specific platform or tool. This modularity allows you to compose a custom global ignore set that matches your exact development environment.

## Selecting Templates from the github/gitignore Repository

The repository organizes global templates in the `Global/` directory. Choose files that match your operating systems and development tools:

- **Operating System Templates**: `Global/Linux.gitignore` contains generic temporary-file patterns like `*.swp` and `*.tmp`. `Global/macOS.gitignore` handles macOS-specific files including `.DS_Store` and `._*` resource forks. `Global/Windows.gitignore` includes Windows thumbnail caches and `Thumbs.db`.
- **Editor-Specific Templates**: Files like `Global/Vim.gitignore`, `Global/Emacs.gitignore`, and `Global/VisualStudioCode.gitignore` provide patterns for swap files, backup copies, undo files, and workspace storage generated by your development environment.

## Setting Up Your Global gitignore File

### Step 1: Assemble Your Global Ignore File

Create a single master file (commonly `~/.gitignore_global`) by concatenating the relevant templates from the github/gitignore repository:

```bash

# Create the global ignore file from selected templates

cat ~/gitignore-templates/Global/Linux.gitignore \
    ~/gitignore-templates/Global/macOS.gitignore \
    ~/gitignore-templates/Global/Vim.gitignore \
    > ~/.gitignore_global

```

Alternatively, manually copy the specific patterns you need from `Global/Linux.gitignore`, `Global/macOS.gitignore`, or other relevant files in the repository into your new global file.

### Step 2: Configure Git to Use the Global File

Run the following command once to set the global excludes file path:

```bash
git config --global core.excludesfile ~/.gitignore_global

```

This configuration writes to your global Git configuration and persists across all repositories on your machine.

### Step 3: Verify the Configuration

Test that your patterns work correctly using Git's `check-ignore` command:

```bash
git check-ignore -v ~/myproject/test.swp

```

The output should reference your global file (`~/.gitignore_global`) and the specific pattern that matches, confirming that temporary files will be ignored across all projects.

## Maintaining Your Global Ignore List

The github/gitignore repository receives regular updates as new tools and operating system versions introduce different temporary file patterns. To keep your global configuration current, periodically pull the latest templates from the repository and refresh your assembled global file. This approach allows you to add support for new editors or OS updates by simply including additional files from the `Global/` directory, such as `Global/VisualStudioCode.gitignore` when adopting a new editor.

## Summary

- Git's `core.excludesfile` configuration creates a global ignore layer that applies to all repositories after checking local `.gitignore` files.
- The github/gitignore repository provides platform-specific templates in `Global/Linux.gitignore`, `Global/macOS.gitignore`, and `Global/Windows.gitignore` for OS temporary files.
- Editor-specific patterns are available in dedicated files like `Global/Vim.gitignore` and `Global/VisualStudioCode.gitignore`.
- Combine selected templates into a single file (e.g., `~/.gitignore_global`) and activate it with `git config --global core.excludesfile ~/.gitignore_global`.
- Use `git check-ignore -v` to verify that temporary files match your global patterns.

## Frequently Asked Questions

### What is the difference between .gitignore and core.excludesfile?

The `.gitignore` file is repository-specific and intended for project artifacts like build outputs and dependencies. The `core.excludesfile` is a user-specific global configuration that applies across all repositories on your machine, making it ideal for personal editor settings and operating system files that should never be committed to any project.

### Where should I store my global gitignore file?

While you can store the file anywhere accessible to Git, common locations include `~/.gitignore_global` in your home directory or `~/.config/git/ignore` on Unix-like systems. The location is less important than ensuring the full path is correctly specified in your Git configuration using `git config --global core.excludesfile`.

### Will global ignore patterns override my project's .gitignore?

No, global patterns complement rather than override project-specific rules. Git processes ignore patterns in a specific order: first the local `.gitignore`, then the global excludes file. Note that once a file is ignored by the global configuration, it cannot be un-ignored locally using `!` negation patterns in the repository `.gitignore`.

### Can I use github/gitignore templates directly without downloading them?

No, Git requires the actual file content to be present on your local filesystem. You must clone the github/gitignore repository or download the specific `Global/` files you need, then concatenate them into your local `core.excludesfile`. While you can reference the GitHub URLs for documentation, the ignore patterns must exist locally for Git to parse them.