首頁·終端機命令

git config

git

用法

git config [--global] <key> [<value>]

讀寫 git 的設定;不加 --global 只會寫進目前的儲存庫,重新複製一份就沒有這條設定了。

常用選項

選項含義
--globalwrite to ~/.gitconfig for every repository
--localwrite to .git/config, the default
--list --show-originprint every setting and the file it came from
--get <key>print one value
--unset <key>delete one setting
-eopen the config file in your editor

範例

git config --global user.email "me@example.com"

sets the address every future commit is signed with

git config --global init.defaultBranch main

new repositories start on main instead of master

git config --list --show-origin

shows which file each setting comes from

難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. git config 是做什麼的?

讀寫 git 的設定;不加 --global 只會寫進目前的儲存庫,重新複製一份就沒有這條設定了。

Q. 怎麼寫?

git config [--global] <key> [<value>] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 6 個,完整列表在 man git。這條命令屬於git。

相關命令

man 手冊: man git-config