Git Notes
Master Git configuration including user identity, editor setup, SSH keys, line endings, aliases, and per-repository settings for optimal development workflow across projects.
Git configuration controls how Git behaves on your system. This comprehensive guide covers all essential and advanced configurations for productivity and best practices.
Global vs Local Configuration
Configuration Hierarchy: Local settings override global, global overrides system. Run at appropriate level for your needs.
Required Configuration
User Identity (MUST DO FIRST)
# Global (all repositories)
git config --global user.name "Your Full Name"
git config --global user.email "your@email.com"
# Local (specific repository)
cd /path/to/repo
git config user.name "Your Full Name"
git config user.email "your@email.com"
# System-wide (all users)
sudo git config --system user.name "Name"Why required: Every commit records user.name and user.email. Required for GitHub authorship tracking.
Essential Configurations
Default Editor
# For commit messages, interactive operations
git config --global core.editor "nano"
# or: vim, code, gedit, emacs, subl
# VS Code with wait flag (waits for you to save)
git config --global core.editor "code --wait"
# Nano (recommended for beginners)
git config --global core.editor "nano"Default Branch Name
# Modern repositories use 'main' not 'master'
git config --global init.defaultBranch mainLine Ending Handling
# For Windows users (convert CRLF ↔ LF)
git config --global core.autocrlf true
# For Mac/Linux users (preserve LF)
git config --global core.autocrlf input
# No conversion (not recommended)
git config --global core.autocrlf falseLine Ending Problem:
Windows
(CRLF)
Unix/Mac
(LF)
core.autocrlf settings:
├─ true: Checkout Windows, commit Unix
├─ input: Preserve Unix in repo
└─ false: No conversion (avoid)
Pull Behavior
# Merge strategy (default)
git config --global pull.rebase false
# Rebase strategy (keep linear history)
git config --global pull.rebase true
# Only fast-forward
git config --global pull.ff onlyAliases (Productivity Shortcuts)
Common Aliases
# Short command aliases
git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.ci "commit"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "log --graph --oneline --all"Complex Aliases
# View formatted log
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# Status with branch
git config --global alias.s "status -sb"
# Add with prompt
git config --global alias.add-interactive "add --interactive"
# Undo last commit (keep changes)
git config --global alias.undo "reset --soft HEAD~1"Using Aliases
# Instead of: git status
git st
# Instead of: git checkout feature/login
git co feature/login
# Instead of: git log --graph --oneline --all
git visualCredential Management
Password Caching
# Store credentials in memory for 15 minutes
git config --global credential.helper cache
# Cache for 1 hour (3600 seconds)
git config --global credential.helper "cache --timeout=3600"Persistent Storage
Windows:
git config --global credential.helper manager
# or: winstoremacOS:
git config --global credential.helper osxkeychainLinux:
git config --global credential.helper store
# or: gnome-keyring, passColor Output
# Enable colored output (recommended)
git config --global color.ui true
# Or fine-grained control:
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive autoWhitespace & Formatting
# Show whitespace issues
git config --global core.whitespace "space-before-tab, trailing-space"
# Tab size in diffs
git config --global core.pager "less -x4"SSL/Security
# Disable SSL verification (NOT recommended for production)
git config --global http.sslVerify false
# Use system certificates
git config --global http.sslBackend schannel # Windows
git config --global http.sslBackend openssl # OthersMerge Conflict Tools
# Use VS Code for merge conflicts
git config --global merge.tool code
git config --global mergetool.code.cmd "code --wait --merge $REMOTE $LOCAL $BASE $MERGED"
# View conflicts
git mergetoolView Configuration
List All Settings
# Global config
git config --list
# With origins
git config --list --show-origin
# Local only
git config --list --local
# Global only
git config --list --globalView Specific Values
git config user.name
git config user.email
git config core.editor
git config core.autocrlfConfiguration File Examples
Global Config (~/.gitconfig)
Local Config (.git/config)
SSH Configuration
# Generate SSH key
ssh-keygen -t ed25519 -C "your@email.com"
# Configure SSH for Git
git config --global core.sshCommand "ssh -i ~/.ssh/id_ed25519 -F /dev/null"Global Gitignore
# Create global ignore file
cat > ~/.gitignore_global << 'EOF'
# IDE
.vscode/
.idea/
*.swp
*~
# OS
.DS_Store
Thumbs.db
# Environment
.env
.env.local
EOF
# Apply configuration
git config --global core.excludesfile ~/.gitignore_globalPerformance Optimization
# For large repositories
git config --global core.fscache true
# Parallel thread handling
git config --global core.preloadindex true
# Large file support
git config --global core.longpaths trueInterview Q&A
Q1: What's the first configuration you do after installing Git?
A: Configure user identity: git config --global user.name "Name" and user.email "email@example.com". These are required for commits to be attributed correctly. Set default branch with init.defaultBranch main and editor with core.editor "nano" or preferred editor.
Q2: Difference between global and local Git configuration?
A: Global configuration (~/.gitconfig) applies to all repositories on your system. Local configuration (.git/config) applies only to specific repository and overrides global settings. Use global for personal settings, local for project-specific settings (e.g., different email for work repository).
Q3: What does core.autocrlf do and when to use each setting?
A: core.autocrlf handles line ending differences between Windows (CRLF) and Unix (LF). Set true on Windows for cross-platform projects. Set input on Mac/Linux. The true setting converts CRLF to LF on commits, preserving Unix format in repository while allowing Windows line endings locally.
Q4: How do you view all Git configuration settings?
A: Run git config --list to show all active settings (system, global, local combined). Run git config --list --global for only global settings. Run git config --list --show-origin to see file location of each setting. Run git config --global --list for global settings. Query specific value with git config user.name.
Q5: Why create aliases and what's an example workflow?
A: Aliases reduce typing for frequent commands, increasing productivity. Example aliases: st for status, co for checkout, br for branch. Instead of typing git status, just type git st. Complex aliases like lg can format log output nicely. Define with git config --global alias.st "status".
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Configure Git - User Identity and Settings.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, setup, configure, configure git - user identity and settings
Related Git & GitHub Topics