深入Git配置

git配置

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

添加配置

git config 参数名 "value" # 添加本仓库配置
git config --global 参数名 "value" # 添加全局配置

配置全局用户信息

git config --global user.name ""  # 配置用户名
git config --global user.email "" # 配置邮箱

配置仓库用户信息

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

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

配置pull rebase

git config --global pull.rebase true 

默认时,git pull = git fetch+git merge
添加如上配置后,git pull = git pull --rebase

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

删除配置

git config --global --unset 参数名  
git config --unset 参数名 

参考

Git提交时出现Merge branch ‘master’ of …之解决方法

相关推荐

  1. 深入Git配置

    2024-04-21 07:48:01       29 阅读
  2. <span style='color:red;'>Git</span><span style='color:red;'>配置</span>

    Git配置

    2024-04-21 07:48:01      43 阅读
  3. vscode 配置git

    2024-04-21 07:48:01       39 阅读
  4. git环境配置

    2024-04-21 07:48:01       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-21 07:48:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-21 07:48:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-21 07:48:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-21 07:48:01       20 阅读

热门阅读

  1. rk3568 ubuntu修改IP地址

    2024-04-21 07:48:01       17 阅读
  2. Android 13 - Media框架(33)- ACodec(九)

    2024-04-21 07:48:01       33 阅读
  3. TCP三次握手的原因

    2024-04-21 07:48:01       37 阅读
  4. 深度学习基础——卷积神经网络的基础模块

    2024-04-21 07:48:01       19 阅读
  5. 基于Kubernetes集群1.27.3构建ElasticSearch-7集群

    2024-04-21 07:48:01       17 阅读
  6. .NET 设计模式—备忘录模式(Memento Pattern)

    2024-04-21 07:48:01       22 阅读
  7. Linux中文件特殊权限suid、sgid、sticky详解

    2024-04-21 07:48:01       18 阅读
  8. qt_standard_project_setup

    2024-04-21 07:48:01       20 阅读
  9. 设计模式(020)行为型之备忘录模式

    2024-04-21 07:48:01       19 阅读