# 全域設定 (所有專案套用)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# 專案層級設定 (覆蓋全域)
git config user.name "Project Name"
git config user.email "project@example.com"
# 系統層級 (所有使用者)
git config --system alias.ci commit
git config --system alias.st status
git config --system alias.co checkout
git config --system alias.br branch
git config --system alias.lg "log --oneline --graph --decorate --all"
git config --system alias.unstage "reset HEAD --"
git config --system alias.last "log -1 HEAD"
# 或寫入 ~/.gitconfig (全域)
git config --global alias.ci commit
# ...
使用範例:git ci -m "msg"、git st、git lg、git br
| 層級 | 範圍 | 編輯指令 | 檔案位置 |
|---|---|---|---|
| --local (預設) | 當前專案 | git config -e | .git/config |
| --global | 當前使用者 | git config -e --global | ~/.gitconfig |
| --system | 全系統所有使用者 | git config -e --system | /etc/gitconfig |
| 指令 | 用途 |
|---|---|
git status | 查看工作區/暫存區狀態 |
git add <file> | 將檔案加入暫存區 |
git commit -m "msg" | 提交暫存區變更 |
git push | 推送至遠端 |
git pull | 拉取遠端更新並合併 |
git branch | 列出/建立分支 |
git checkout <branch> | 切換分支 |
git merge <branch> | 合併分支 |
git log --oneline --graph | 視覺化提交歷史 |
# 編譯輸出
target/
*.class
# IDE
.idea/
*.iml
.vscode/
.settings/
.project
.classpath
# 建構工具
.mvn/
gradle/
build/
# 系統
.DS_Store
Thumbs.db
# 敏感資訊
*.pem
*.key
local.properties
Git 基礎設定三部曲:**身分設定 → 別名定義 → 理解三層設定檔**。配合 git init/clone 建立倉庫、.gitignore 排除雜訊、核心工作流指令肌肉記憶,即可順暢展開版本控制之旅。