From 009888dd3129e8b8a7868a15c41901f003abbaa1 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Fri, 5 Sep 2025 15:00:00 +0800 Subject: [PATCH] feat: add comprehensive Git configuration --- git/.gitconfig | 138 ++++++++++++++++++++++++++++++++++++++++++ git/.gitignore_global | 109 +++++++++++++++++++++++++++++++++ git/README.md | 112 ++++++++++++++++++++++++++++++++++ 3 files changed, 359 insertions(+) create mode 100644 git/.gitconfig create mode 100644 git/.gitignore_global create mode 100644 git/README.md diff --git a/git/.gitconfig b/git/.gitconfig new file mode 100644 index 0000000..2776a0e --- /dev/null +++ b/git/.gitconfig @@ -0,0 +1,138 @@ +[user] + # Set your name and email + name = your_name + email = your_email@example.com + +[core] + # Use UTF-8 encoding + quotepath = false + # Use nvim as default editor + editor = nvim + # Handle line endings automatically + autocrlf = true + # Improve performance on Windows + fscache = true + # Enable parallel index preload + preloadindex = true + +[color] + ui = auto + branch = auto + diff = auto + status = auto + +[color "branch"] + current = yellow reverse + local = yellow + remote = green + +[color "diff"] + meta = yellow bold + frag = magenta bold + old = red bold + new = green bold + +[color "status"] + added = green + changed = yellow + untracked = red + +[alias] + # Common shortcuts + st = status + co = checkout + br = branch + ci = commit + cp = cherry-pick + + # Commit aliases + cm = commit -m + ca = commit --amend + can = commit --amend --no-edit + + # Log aliases + lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative + lga = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all + ls = log --pretty=format:'%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]' --decorate + ll = log --pretty=format:'%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]' --decorate --numstat + last = log -1 HEAD --stat + + # Diff aliases + df = diff + dfc = diff --cached + dft = difftool + + # Branch management + brd = branch -d + brD = branch -D + bra = branch -a + + # Remote management + rao = remote add origin + rso = remote show origin + rpo = remote prune origin + + # Stash management + sl = stash list + sa = stash apply + ss = stash save + sp = stash pop + sd = stash drop + + # Reset aliases + unstage = reset HEAD -- + undo = reset --soft HEAD^ + + # Other useful commands + aliases = config --get-regexp alias + contributors = shortlog --summary --numbered + ignored = ls-files --others --ignored --exclude-standard + untracked = ls-files --others --exclude-standard + + # Advanced workflows + sync = !git fetch origin && git rebase origin/$(git rev-parse --abbrev-ref HEAD) + cleanup = !git branch --merged | grep -v '\\*\\|main\\|master\\|develop' | xargs -n 1 git branch -d + wip = !git add -A && git commit -m 'WIP' --no-verify + unwip = !git log -n 1 | grep -q 'WIP' && git reset HEAD~1 + +[push] + # Push current branch to upstream + default = current + # Push tags automatically + followTags = true + +[pull] + # Rebase instead of merge on pull + rebase = true + +[fetch] + # Prune deleted remote branches + prune = true + +[rebase] + # Automatically stash before rebase + autoStash = true + +[merge] + # Use better diff algorithm + conflictStyle = diff3 + # Include summaries of merged commits + log = true + +[diff] + # Better diff algorithm + algorithm = histogram + # Enable rename detection + renames = true + # Detect copies as well as renames + copies = true + +[help] + # Auto-correct misspelled commands + autocorrect = 1 + +[credential] + helper = wincred + +[init] + defaultBranch = main diff --git a/git/.gitignore_global b/git/.gitignore_global new file mode 100644 index 0000000..fcacd9b --- /dev/null +++ b/git/.gitignore_global @@ -0,0 +1,109 @@ +# Windows +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ +*.lnk + +# macOS +.DS_Store +.AppleDouble +.LSOverride +Icon +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Linux +*~ +.directory +.Trash-* + +# IDEs and Editors +.vscode/ +.idea/ +*.swp +*.swo +*~ +.project +.classpath +.settings/ +*.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 +*.so +.Python +env/ +venv/ +ENV/ +*.egg-info/ +dist/ +build/ +.pytest_cache/ + +# Go +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.test +*.out +vendor/ + +# Rust +target/ +Cargo.lock + +# Java +*.class +*.jar +*.war +*.ear +.gradle/ +build/ + +# C/C++ +*.o +*.obj +*.exe +*.out +*.app + +# Logs +logs/ +*.log + +# Environment variables +.env +.env.local +.env.*.local + +# Temporary files +*.tmp +*.temp +*.bak +*.backup + +# Archives +*.zip +*.tar.gz +*.rar +*.7z diff --git a/git/README.md b/git/README.md new file mode 100644 index 0000000..4fa1cd9 --- /dev/null +++ b/git/README.md @@ -0,0 +1,112 @@ +# Git Configuration + +Optimized Git configuration with useful aliases and settings for enhanced workflow. + +## Features + +- **Comprehensive Aliases**: Shortcuts for common Git operations +- **Better Diff Algorithm**: Histogram algorithm for cleaner diffs +- **Auto-correction**: Automatically fixes typos in Git commands +- **Smart Defaults**: Optimized settings for better performance on Windows +- **Global Gitignore**: Ignore common system and IDE files across all repositories + +## Installation + +### Configure Git + +```powershell +# Copy the config to your home directory +Copy-Item git\.gitconfig ~\.gitconfig + +# Configure global gitignore +git config --global core.excludesfile ~/.gitignore_global +Copy-Item git\.gitignore_global ~\.gitignore_global + +# Set your user information +git config --global user.name "Your Name" +git config --global user.email "your.email@example.com" +``` + +## Useful Aliases + +### Basic Operations +- `git st` - Status +- `git co` - Checkout +- `git br` - Branch +- `git cm "message"` - Commit with message +- `git ca` - Amend last commit +- `git can` - Amend last commit without editing message + +### Logs +- `git lg` - Beautiful graph log +- `git lga` - Beautiful graph log (all branches) +- `git last` - Show last commit with stats + +### Branch Management +- `git brd ` - Delete branch (safe) +- `git brD ` - Force delete branch +- `git bra` - List all branches (including remote) + +### Stash Operations +- `git sl` - Stash list +- `git sa` - Stash apply +- `git ss "message"` - Stash save with message +- `git sp` - Stash pop +- `git sd` - Stash drop + +### Advanced Workflows +- `git sync` - Fetch and rebase current branch +- `git cleanup` - Delete all merged branches (except main/master/develop) +- `git wip` - Quick work-in-progress commit +- `git unwip` - Undo the last WIP commit +- `git unstage ` - Unstage file +- `git undo` - Undo last commit (keep changes) + +### Information +- `git aliases` - List all configured aliases +- `git contributors` - List contributors with commit counts +- `git ignored` - List ignored files +- `git untracked` - List untracked files + +## Configuration Highlights + +### Performance +- `core.fscache = true` - Cache file system operations +- `core.preloadindex = true` - Parallel index preload + +### Auto-stash +- Automatically stash changes before rebase + +### Better Diffs +- Histogram algorithm for cleaner diffs +- Detect renames and copies +- Show conflict markers in diff3 style + +### Smart Defaults +- Auto-prune deleted remote branches +- Rebase instead of merge on pull +- Push current branch by default +- Auto-correct typos in commands + +## Windows-Specific Settings + +- `core.autocrlf = true` - Handle line endings automatically +- `credential.helper = wincred` - Use Windows Credential Manager +- `core.editor = nvim` - Use Neovim as default editor + +## Global Gitignore + +The `.gitignore_global` file ignores common files across all your repositories: +- System files (Windows, macOS, Linux) +- IDE and editor files (.vscode, .idea, etc.) +- Language-specific files (node_modules, __pycache__, etc.) +- Temporary and backup files + +## Customization + +Edit `~\.gitconfig` to customize settings to your preferences. Remember to update your user information: + +```powershell +git config --global user.name "Your Name" +git config --global user.email "your.email@example.com" +```