← 返回命令列表

Linux command

git-config 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Set user name

git config --global user.name "[Name]"

Set user email

git config --global user.email "[email@example.com]"

Get a value

git config user.name

Set the default branch name

git config --global init.defaultBranch main

Create a command alias

git config --global alias.co checkout

Remove a setting

git config --global --unset [key]

List all settings

git config --list --show-origin

Edit config file

git config --global --edit

说明

git config manages Git configuration variables that control all aspects of Git's behavior, from user identity and commit settings to advanced options like merge strategies, credential helpers, and performance tuning. Configuration is stored in INI-style text files at three hierarchical levels. System-level configuration (/etc/gitconfig) applies to all users on the system and requires administrator privileges to modify. Global configuration (~/.gitconfig or ~/.config/git/config) applies to the current user across all repositories. Local configuration (.git/config) applies only to the specific repository. Settings at lower levels override higher levels, allowing project-specific customization. Common configuration tasks include setting user identity (user.name and user.email, required for commits), defining command aliases (alias.*), configuring merge and diff tools (merge.tool, diff.tool), setting default branch names (init.defaultBranch), and managing credentials (credential.helper).

参数

--global
User-level config (~/.gitconfig).
--local
Repository config (.git/config).
--system
System-wide config.
--list, -l
List all variables.
--edit, -e
Open config in editor.
--get _NAME_
Get the value for a given key (default behavior when only name is provided).
--get-all _NAME_
Get all values for a multi-valued key.
--unset _NAME_
Remove a setting.
--show-origin
Show the file where each config value comes from.
--help
Display help information.

FAQ

What is the git-config command used for?

git config manages Git configuration variables that control all aspects of Git's behavior, from user identity and commit settings to advanced options like merge strategies, credential helpers, and performance tuning. Configuration is stored in INI-style text files at three hierarchical levels. System-level configuration (/etc/gitconfig) applies to all users on the system and requires administrator privileges to modify. Global configuration (~/.gitconfig or ~/.config/git/config) applies to the current user across all repositories. Local configuration (.git/config) applies only to the specific repository. Settings at lower levels override higher levels, allowing project-specific customization. Common configuration tasks include setting user identity (user.name and user.email, required for commits), defining command aliases (alias.*), configuring merge and diff tools (merge.tool, diff.tool), setting default branch names (init.defaultBranch), and managing credentials (credential.helper).

How do I run a basic git-config example?

Run `git config --global user.name "[Name]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --global do in git-config?

User-level config (~/.gitconfig).