Skip to content

Instantly share code, notes, and snippets.

@JakubAndrysek
Last active August 12, 2025 13:19
Show Gist options
  • Save JakubAndrysek/76b9a988e3f5172af82ecfe45f268f57 to your computer and use it in GitHub Desktop.
Save JakubAndrysek/76b9a988e3f5172af82ecfe45f268f57 to your computer and use it in GitHub Desktop.
Local .gitignore Setup Guide

Local .gitignore Setup Guide

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.

1. Edit local Git config

git config --local -e

Add:

[core]
    excludesfile = ~/Documents/my_repo/.local_gitignore

2. Create your local ignore file

touch ~/Documents/my_repo/.local_gitignore

Add patterns you want to ignore locally:

# Example ignores
.local_gitignore
*.log
node_modules/
.env

3. Why use core.excludesfile?

  • 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

Script

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."

Source:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment