How to create a global .gitignore file

Creating a global .gitignore file allows you to ignore files across all Git repositories on your system, providing consistent file exclusion without duplicating patterns in every project. As the creator of CoreUI with 25 years of development experience since 2000, I’ve configured global .gitignore files on development machines to automatically exclude OS-specific files, editor configurations, and personal tools across all projects. The most efficient approach involves creating a global ignore file and configuring Git to use it system-wide through the core.excludesfile setting. This method ensures consistent ignore behavior across all repositories while reducing project-specific .gitignore maintenance overhead.

Create a global .gitignore file and configure Git to use it across all repositories with core.excludesfile setting.

# Create global .gitignore file in home directory
touch ~/.gitignore_global

# Add common patterns for your system
cat << 'EOF' > ~/.gitignore_global
# macOS
.DS_Store
.AppleDouble
.LSOverride
Icon?
._*

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Linux
*~
.fuse_hidden*
.Trash-*

# IDEs and editors
.vscode/
.idea/
*.swp
*.swo
*~
.sublime-workspace

# Personal tools
*.log
.notes
personal_notes.md

# Backup files
*.bak
*.backup
*.old
EOF

# Configure Git to use global .gitignore
git config --global core.excludesfile ~/.gitignore_global

# Verify configuration
git config --global --get core.excludesfile

This global .gitignore configuration creates a system-wide ignore file containing patterns for OS-specific files, common editor configurations, and personal development tools that should never be tracked in any repository. The git config --global core.excludesfile command tells Git to apply these ignore patterns across all repositories on your system. This approach separates personal environment concerns from project-specific ignore requirements, ensuring cleaner project .gitignore files focused only on project-related exclusions.

Best Practice Note:

This is the global .gitignore setup we recommend for CoreUI development teams to maintain consistent, clean repositories across different operating systems. Keep the global file focused on system and tool-specific patterns while using project .gitignore files for project-specific build artifacts and dependencies.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.

Answers by CoreUI Core Team