This guide shows how to configure a local-only .gitignore
using core.excludesfile
for a specific repository, so you can keep personal ignores without affecting the repository’s .gitignore
file.
git config --local -e
Add:
[core]
excludesfile = ~/Documents/my_repo/.local_gitignore
touch ~/Documents/my_repo/.local_gitignore
Add patterns you want to ignore locally:
# Example ignores
.local_gitignore
*.log
node_modules/
.env
- Keeps the repo’s
.gitignore
clean - Patterns apply only for you
- Great for ignoring editor/OS-specific files
- Keeps your personal preferences separate from the project
local-gitignore.sh
#!/usr/bin/env bash
set -e
# Local GitIgnore Setup Script
# This will configure a per-repo local ignore file using core.excludesfile
# Get repo root
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || true)
if [ -z "$REPO_ROOT" ]; then
echo "❌ Not inside a Git repository."
exit 1
fi
LOCAL_IGNORE_FILE="$REPO_ROOT/.local_gitignore"
echo "📍 Repository root: $REPO_ROOT"
# Step 1: Configure local Git to use this file
git config --local core.excludesfile "$LOCAL_IGNORE_FILE"
echo "✅ Configured local core.excludesfile → $LOCAL_IGNORE_FILE"
# Step 2: Create the ignore file if missing
if [ ! -f "$LOCAL_IGNORE_FILE" ]; then
cat > "$LOCAL_IGNORE_FILE" <<EOF
# Local gitignore - patterns here apply only to you
.local_gitignore
*.log
node_modules/
.env
EOF
echo "✅ Created $LOCAL_IGNORE_FILE with sample patterns"
else
echo "ℹ️ $LOCAL_IGNORE_FILE already exists."
fi
# Step 3: Show confirmation
echo
echo "🎯 Done! Your local ignore file is ready."
echo " You can now edit: $LOCAL_IGNORE_FILE"
echo
echo "💡 This affects only your local repo and won't touch .gitignore in commits."