深入Git配置

git配置

shell 复制代码
git config -h
usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-pattern]
    --get-all             get all values: key [value-pattern]
    --get-regexp          get values for regexp: name-regex [value-pattern]
    --get-urlmatch        get value specific for the URL: section[.var] URL
    --replace-all         replace all matching variables: name value [value-pattern]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-pattern]
    --unset-all           remove all matches: name [value-pattern]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    --fixed-value         use string equality when comparing values to 'value-pattern'
    -e, --edit            open an editor
    --get-color           find the color configured: slot [default]
    --get-colorbool       find the color setting: slot [stdout-is-tty]

Type
    -t, --type <>         value is given this type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --bool-or-str         value is --bool or string
    --path                value is a path (file or directory name)
    --expiry-date         value is an expiry date

Other
    -z, --null            terminate values with NUL byte
    --name-only           show variable names only
    --includes            respect include directives on lookup
    --show-origin         show origin of config (file, standard input, blob, command line)
    --show-scope          show scope of config (worktree, local, global, system, command)
    --default <value>     with --get, use default value when missing entry

添加配置

shell 复制代码
git config 参数名 "value" # 添加本仓库配置
git config --global 参数名 "value" # 添加全局配置

配置全局用户信息

shell 复制代码
git config --global user.name ""  # 配置用户名
git config --global user.email "" # 配置邮箱

配置仓库用户信息

shell 复制代码
cd repo # 进入git仓库目录
git config user.name ""  # 配置用户名
git config user.email "" # 配置邮箱

不同的仓库可能来自不同的平台有github、gitlab、gitee等,通过配置仓库用户信息可以更好的区分不同平台的账户。

配置pull rebase

shell 复制代码
git config --global pull.rebase true 

默认时,git pull = git fetch+git merge

添加如上配置后,git pull = git pull --rebase

经常会出现很多的 Merge branch 'master' of ... 污染commit 信息,通过该配置可以避免出现这种污染。

删除配置

shell 复制代码
git config --global --unset 参数名  
git config --unset 参数名 

参考

Git提交时出现Merge branch 'master' of ...之解决方法

相关推荐
习惯就好zz3 小时前
Git 交互式 rebase 实战:将后续修改合并到历史提交
git
南棱笑笑生10 小时前
20260429给万象奥科的开发板HD-RK3576-PI适配瑞芯微原厂的Android14时删除全部的.git目录
git·rockchip
tsyjjOvO11 小时前
【Git 从入门到实战】(IDEA+Gitee 版)
git·gitee·idea
你知道“铁甲小宝”吗丶12 小时前
git推送到多平台(gitee/github)
git·gitee·github
bksczm12 小时前
Linux之基础开发工具之git
git
GUET_一路向前12 小时前
【git工作常用指令】
大数据·git·elasticsearch
handler0113 小时前
Git 核心指令速查
linux·c语言·c++·笔记·git·学习
二宝哥13 小时前
大数据之yum安装git
git
牛奶咖啡1314 小时前
Git实践——git远程仓库操作
git·git远程仓库的创建·github创建仓库·git将本地仓库推送到远程仓库·使用git克隆远程仓库到本地·git分支的创建与合并·git冲突的产生与解决
随风,奔跑15 小时前
Git学习笔记
笔记·git·学习