Sign In Create Account
Configuration

Git Configuration

Set up consistent Git configuration and global settings for professional development workflows.

Essential Git Configuration

Configure Git with these essential settings for consistent behavior across all repositories.

Basic Git Configuration

# Basic identity (required)
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# Default branch name
git config --global init.defaultBranch main

# Better diffs and merges
git config --global diff.tool vimdiff
git config --global merge.tool vimdiff
git config --global diff.colorMoved zebra

# Better handling of line endings
git config --global core.autocrlf input  # Linux/Mac
git config --global core.autocrlf true   # Windows

# Rebase on pull by default (cleaner history)
git config --global pull.rebase true

# Prune remote branches on fetch
git config --global fetch.prune true

# Better push behavior
git config --global push.default simple
git config --global push.followTags true

Configuration Benefits

  • Consistent Identity: Proper attribution in commits
  • Better Defaults: Safer and more intuitive Git behavior
  • Cleaner History: Automatic rebasing and pruning
  • Cross-Platform: Proper line ending handling

Helpful Git Aliases

Speed up your workflow with these essential Git aliases.

Basic Aliases

Essential Git Aliases

# Basic command shortcuts
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit

# Useful shortcuts
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual '!gitk'

Advanced Aliases

Advanced Git Aliases

# Beautiful log output
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"

# Branch management
git config --global alias.branches "branch -a"
git config --global alias.remotes "remote -v"
git config --global alias.cleanup "!git branch --merged | grep -v '\*\|main\|develop' | xargs -n 1 git branch -d"

# Stash operations
git config --global alias.sl "stash list"
git config --global alias.sa "stash apply"
git config --global alias.ss "stash save"
git config --global alias.sd "stash drop"

# Undoing operations
git config --global alias.uncommit "reset --soft HEAD~1"
git config --global alias.unstage "reset HEAD --"
git config --global alias.undo "checkout --"

# Interactive operations
git config --global alias.fixup "commit --fixup"
git config --global alias.autosquash "rebase -i --autosquash"

# Show type and content of Git objects
git config --global alias.type "cat-file -t"
git config --global alias.dump "cat-file -p"

Alias Usage Examples

# Instead of typing long commands:
git status
git log --oneline --graph --decorate --all
git branch --merged | grep -v '\*\|main' | xargs -n 1 git branch -d

# Use short aliases:
git st
git lg  
git cleanup

Global .gitignore

Create a global .gitignore file for common files that should never be committed across all projects.

Create Global .gitignore

# Create the global gitignore file
touch ~/.gitignore_global

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

~/.gitignore_global

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Desktop.ini

# Editor files
.vscode/
.idea/
*.swp
*.swo
*~
.sublime-project
.sublime-workspace

# Node.js
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.npm
.eslintcache

# Python
__pycache__/
*.py[cod]
*$py.class
.Python
*.so
.coverage
htmlcov/
.pytest_cache/
venv/
env/
.venv/

# Logs
logs/
*.log

# Runtime data  
pids/
*.pid
*.seed
*.pid.lock

# Temporary files
tmp/
temp/
*.tmp
*.temp

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

# Archives
*.zip
*.tar.gz
*.rar

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# IDE workspace files
.vscode/settings.json
.vscode/launch.json
.vscode/extensions.json
*.code-workspace

# JetBrains IDEs
.idea/
*.iml
*.iws

# Vim
*.swp
*.swo
*~

# Emacs
*~
#*#
/.emacs.desktop
/.emacs.desktop.lock
*.elc

Global .gitignore Benefits

  • Consistency: Same ignored files across all projects
  • Clean Repositories: No accidental commits of system files
  • Less Maintenance: Don't need to add common ignores to each project
  • Personal Preference: Ignore your editor/OS specific files

Security and Signing

Configure Git for secure commit signing and credential management.

GPG Commit Signing

Sign your commits with GPG for verification and security.

GPG Signing Setup

# List existing GPG keys
gpg --list-secret-keys --keyid-format LONG

# Generate a new GPG key (if needed)
gpg --full-generate-key

# Get your GPG key ID (replace with your key ID)
gpg --list-secret-keys --keyid-format LONG

# Configure Git to use GPG signing
git config --global user.signingkey YOUR_GPG_KEY_ID
git config --global commit.gpgsign true
git config --global tag.gpgsign true

# Export public key to add to GitHub/GitLab
gpg --armor --export YOUR_GPG_KEY_ID

Credential Management

Credential Helper Setup

# macOS: Use keychain
git config --global credential.helper osxkeychain

# Windows: Use Windows Credential Manager
git config --global credential.helper manager

# Linux: Use libsecret
git config --global credential.helper libsecret

# Or use cache with timeout (in seconds)
git config --global credential.helper 'cache --timeout=3600'

Performance and Optimization

Performance Configuration

# Enable parallel operations
git config --global pack.threads 0

# Optimize for large repositories
git config --global core.preloadindex true
git config --global core.fscache true

# Better garbage collection
git config --global gc.auto 256

# Enable file system monitoring (if available)
git config --global core.fsmonitor true

# Optimize status operations
git config --global status.showUntrackedFiles normal

# Better diff algorithm
git config --global diff.algorithm patience

# Enable renames detection
git config --global diff.renames copies

Large Repository Tips

  • • Use partial clones: git clone --filter=blob:none
  • • Enable file system cache on Windows
  • • Consider Git LFS for large binary files
  • • Use shallow clones for CI: git clone --depth=1

Verification and Maintenance

Verify Configuration

# View all global configuration
git config --global --list

# View specific configuration
git config --global user.name
git config --global user.email

# View configuration source (where setting is defined)
git config --show-origin user.name

# Edit global configuration directly
git config --global --edit

Configuration File Locations

  • System: /etc/gitconfig (affects all users)
  • Global: ~/.gitconfig (affects current user)
  • Local: .git/config (affects current repository)
  • Priority: Local → Global → System