1. 创建全局 Git Ignore 文件:

    touch ~/.gitignore_global
    
  2. 添加以下内容到 .gitignore_global 文件中:

    # =========================
    # macOS
    # =========================
    .DS_Store
    .AppleDouble
    .LSOverride
    .Icon
    ._*
    .DocumentRevisions-V100
    .fseventsd
    .Spotlight-V100
    .TemporaryItems
    .Trashes
    .VolumeIcon.icns
    .com.apple.timemachine.supported
    .AppleDB
    .AppleDesktop
    .apdisk
    
    # =========================
    # Windows
    # =========================
    Thumbs.db
    desktop.ini
    
    # =========================
    # Linux
    # =========================
    .directory
    .Trash-*
    .recently-used.xbel
    .nfs*
    .fuse_hidden*
    .gvfs/
    
    # =========================
    # Editors / IDEs
    # =========================
    .vscode/
    !.vscode/settings.json
    
    .idea/
    *.iml
    *.code-workspace
    
    *~
    .swp
    *.swp
    *.swo
    *.tmp
    \#*\#
    /.emacs.desktop
    /.emacs.desktop.lock
    *.elc
    auto-save-list/
    tramp
    
    *.sublime-project
    *.sublime-workspace
    
    .vs/
    *.user
    *.suo
    
    # =========================
    # Build Artifacts
    # =========================
    build/
    dist/
    out/
    output/
    .cache/
    .next/
    .nuxt/
    .vuepress/dist
    .turbo/
    .parcel-cache/
    .astro/
    .tmp/
    
    # =========================
    # Python
    # =========================
    __pycache__/
    *.py[cod]
    *$py.class
    *.so
    
    # Virtual envs
    venv/
    env/
    ENV/
    .venv*/
    pyvenv.cfg
    pip-selfcheck.json
    
    # Packaging
    *.egg
    *.egg-info/
    *.dist-info/
    .eggs/
    wheels/
    pip-log.txt
    
    # Testing / Coverage
    .pytest_cache/
    .coverage
    .coverage.*
    coverage/
    htmlcov/
    .tox/
    .nox/
    .hypothesis/
    .mypy_cache/
    .pyre/
    .pytype/
    prof/
    *.prof
    
    # =========================
    # Jupyter / Data Science
    # =========================
    .ipynb_checkpoints/
    *.pkl
    *.joblib
    *.h5
    *.hdf5
    *.parquet
    *.feather
    *.arrow
    *.csv
    *.tsv
    *.xls
    *.xlsx
    
    # =========================
    # Node.js / Frontend
    # =========================
    node_modules/
    npm-debug.log*
    yarn-error.log
    yarn-debug.log
    .pnpm-debug.log
    .npm
    .yarn
    lerna-debug.log
    verdaccio/
    
    react-app-rewired/
    .temp
    .temp.*
    !temp.d.ts
    
    .eslintcache
    .stylelintcache
    .pnp.*
    
    # =========================
    # Java / JVM Languages
    # =========================
    *.class
    *.jar
    *.war
    *.ear
    *.nar
    *.tar.gz
    *.nar
    *.hprof
    .mvn/
    .gradle/
    .gradle-cache/
    target/
    
    # =========================
    # C / C++ / Go / Rust
    # =========================
    *.o
    *.a
    *.out
    *.obj
    *.exe
    *.dll
    *.so
    *.dylib
    *.rlib
    target/
    bin/
    pkg/
    
    # =========================
    # .NET / C#
    # =========================
    *.dll
    *.exe
    *.pdb
    *.mdb
    *.cache
    *.aps
    *.res
    *.tlb
    *.tlh
    *.bak
    *.old
    *.orig
    *.save
    *.userosscache
    *.sln.docstates
    
    # =========================
    # Env / Config
    # =========================
    .env
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local
    .env*.private
    .env*.secret
    .envrc
    !.env.example
    
    # =========================
    # Logs
    # =========================
    logs/
    *.log
    *.log.*
    
    # =========================
    # Database / Local Data
    # =========================
    db.sqlite3
    *.sqlite3
    *.db
    local_settings.py
    
    # =========================
    # Certificates / Keys
    # =========================
    *.pem
    *.key
    *.csr
    
    # =========================
    # Docker / Serverless
    # =========================
    .docker/
    *.docker
    !Dockerfile
    !docker-compose.yml
    docker-compose.override.yml
    
  3. 配置使用全局 .gitignore

    git config --global core.excludesfile ~/.gitignore_global
    
  4. 检查是否生效

    git config --global core.excludesfile