红穆笔记

git config

管理 Git 倉庫的自定義設置項。 這些設置可以分爲局部設置(只對當前倉庫生效)和全局設置(對當前用戶生效)

100% 瀏覽器本地處理 0 數據上傳

常用示例

列出局部設置項(存儲在當前倉庫的 `.git/config`)

git config {{[-l|--list]}} --local

列出全局配置項(存儲在 `~/.gitconfig`)

git config {{[-l|--list]}} --global

列出系統配置項(存儲在 `/etc/gitconfig`),並且展示文件的位置

git config {{[-l|--list]}} --system --show-origin

獲取某個配置項的值

git config alias.unstage

設置某個全局配置項

git config --global alias.unstage "reset HEAD --"

將某個全局配置項恢復爲默認值

git config --global --unset alias.unstage

使用默認編輯器修改本地設置

git config {{[-e|--edit]}}

使用默認編輯器修改全局設置

git config --global {{[-e|--edit]}}

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Manage custom configuration options for Git repositories. These configurations can be local (for the current repository) or global (for the current user). More information

Globally set your name or email (this information is required to commit to a repository and will be included in all commits)

git config --global {{user.name|user.email}} "{{Your Name|[email protected]}}"

List local, global, or system configuration entries and show their file location

git config --{{local|global|system}} {{[-l|--list]}} --show-origin

Set the global value of a given configuration entry (in this case an alias)

git config --global {{alias.unstage}} "reset HEAD --"

Get the value of a given configuration entry

git config {{alias.unstage}}

Use an alias

git {{unstage}}

Revert a global configuration entry to its default value

git config --global --unset {{alias.unstage}}

Edit the local Git configuration (`.git/config`) in the default editor

git config {{[-e|--edit]}}

Edit the global Git configuration (`~/.gitconfig` by default or `$XDG_CONFIG_HOME/git/config` if such a file exists) in the default editor

git config --global {{[-e|--edit]}}

命令信息

命令名git config
用途管理 Git 倉庫的自定義設置項。 這些設置可以分爲局部設置(只對當前倉庫生效)和全局設置(對當前用戶生效)
適用平臺通用
示例數量8 條
官方文檔https://git-scm.com/docs/git-config
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git config 命令是做什麼的?

管理 Git 倉庫的自定義設置項。 這些設置可以分爲局部設置(只對當前倉庫生效)和全局設置(對當前用戶生效)

git config 怎麼用?

頁面按場景列出了8 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

git config 最常用的操作是什麼?

列出局部設置項(存儲在當前倉庫的 `.git/config`):git config {{[-l|--list]}} --local

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。