Git使用git config 指令来指定与git相关的配置
config 配置有system级别、global(用户级别)、和local(当前仓库)三个级别,三个设置范围system-》global-》local 底层配置会覆盖顶层配置 分别使用--system/global/local 可以定位到配置文件
1、查看git的配置列表
我们可以先查看一下git的配置列表:
git config --list
如果没有配置东西,应该是空的。照着下面配置完成后,你可以再试一下该命令,就会出现一系列配置信息。
2、进行配置
(1)命令行配置
git config --global user.name "username"
git config --global user.email "email"
将username和email换成github(或者其它类似远程仓库)的用户名和邮箱。
补充:(1.1) 全局变量
--global 表示全局的,即当前用户都有效,该配置会出现在 ~/.gitconfig 文件中,~表示当前用户的目录,比如我的是:C:\Users\username\.gitconfig ,打开该文件你会发现如下图所示的内容:
对比一下,你应该就知道上面的配置命令是怎么起作用的吧(其它配置命令也是这个意思!)。(注:该文件#开头的行是注释,为了方便理解,你可以自己添加一些注释信息)
(1.2)局部变量
既然有全局的,那么肯定有局部的啊!局部的是不加 --global 的,如下:
git config user.name "username"
git config user.email "email"
局部是只对当前仓库起效的,它的配置信息会在当前仓库根目录/.git/config文件下:
注意:局部变量覆盖全局变量!!!和编程语言里面的变量关系是一样的。
我在上面我新建的那个仓库里,随便提交了一点东西,然后查看提交日志如下:
(2)修改对应文件进行配置
相信看了上面的补充内容之后,你应该已经了解这两个配置命令的作用了吧,所以这里就不详讲了,你找到对应文件,该相关设置就好了。
3、修改已配置的信息
假如配置后,发现有信息配置错了,如何进行修改?
(1)用命令修改
这里演示修改本地仓库的用户名和邮箱:
git config --replace-all user.name "name"
git config --replace-all user.email "123@qq.com"
修改后是这样的:
(2)修改对应文件进行修改
这个应该不用讲了。
4、git config命令的功能列表
(1)git config
我们直接输入git config,就可以看到简单的命令列表了:
$ git config
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-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-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
--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)
--default <value> with --get, use default value when missing entry
(2)git config --help
这个命令默认打开本地git安装目录下的G:\Git\mingw64\share\doc\git-doc\下的详细的说明文档(这里G:\Git为安装目录),这个是详细介绍命令的作用(上面的那个只是简介)。
样例截图:
延伸:其它命令你也可以通过添加 --help 参数来打开命令的相关文档说明,如 git diff --help,……
Git 自带一个
git config
的工具来帮助设置控制 Git 外观和行为的配置变量。 这些变量存储在三个不同的位置:
-
/etc/gitconfig
文件: 包含系统上每一个用户及他们仓库的通用配置。 如果在执行
git config
时带上
--system
选项,那么它就会读写该文件中的配置变量。 (由于它是系统配置文件,因此你需要管理员或超级用户权限来修改它。)
-
~/.gitconfig
或
~/.config/git/config
文件:只针对当前用户。 你可以传递
--global
选项让 Git 读写此文件,这会对你系统上
所有
的仓库生效。
-
当前使用仓库的 Git 目录中的
config
文件(即
.git/config
):针对该仓库。 你可以传递
--local
选项让 Git 强制读写此文件,虽然默认情况下用的就是它。。 (当然,你需要进入某个 Git 仓库中才能让该选项生效。)
每一个级别会覆盖上一级别的配置,所以
.git/config
的配置变量会覆盖
/etc/gitconfig
中的配置变量。
在 Windows 系统中,Git 会查找
$HOME
目录下(一般情况下是
C:\Users\$USER
)的
.gitconfig
文件。 Git 同样也会寻找
/etc/gitconfig
文件,但只限于 MSys 的根目录下,即安装 Git 时所选的目标位置。 如果你在 Windows 上使用 Git 2.x 以后的版本,那么还有一个系统级的配置文件,Windows XP 上在
C:\Documents and Settings\All Users\Application Data\Git\config
,Windows Vista 及更新的版本在
C:\ProgramData\Git\config
。此文件只能以管理员权限通过
git config -f <file>
来修改。
你可以通过以下命令查看所有的配置以及它们所在的文件:
$ git config --list --show-origin
添加GIT全局配置(HTTPS代理)
git config --global https.proxy http://10.224.10.252:808
删除GIT全局配置
git config --unset --global https.proxy
配置GIT第三方编辑器
git config --global core.editor D:/Notepad++/notepad++.ex
详细请查看官方文档介绍
初次运行 Git 前的配置
Git使用git config 指令来指定与git相关的配置config 配置有system级别、global(用户级别)、和local(当前仓库)三个级别,三个设置范围system-》global-》local 底层配置会覆盖顶层配置 分别使用--system/global/local 可以定位到配置文件1、查看git的配置列表我们可以先查看一下git的配置列表:git config --list如果没有配置东西,应该是空的。照着下面配置完成后,你可以再试一下该命令,就会出现一..
Ruby的RVM
ZSH用于外壳,“我的ZSH”用作默认
设置
一个deploy.sh脚本将符号链接
配置
,挂钩并安装RVM和Oh My ZSH。 这非常简单,只需检查其源代码即可。
这些是强制性步骤:
安装依赖项
sudo apt-get install wget curl command-not-found vim
运行deploy.sh
用您的名称/电子邮件更改~/.
git
config
并提交更改
您可能还会喜欢一些额外的东西:
ack-grep在VIM中用作grep命令。 只需安装ack-grep软件包
更改为ZSH和OhMyZSH: sudo apt-get install zsh和chsh -s /bin/zsh (还要检查您的终端模拟器-Kon
用户名和邮箱地址的作用用户名和邮箱地址是本地
git
客户端的一个变量,不随
git
库而改变。每次commit都会用用户名和邮箱纪录。
git
hub的contributions统计就是按邮箱来统计的。
查看
用户名和邮箱地址:$
git
config
user.name$
git
config
user.email修改用户名和邮箱地址:$
git
config
--global user.name "user
在
git
中,我们使用
git
config
命令用来
配置
git
的
配置
文件,
git
配置
级别主要有以下3类:
1、仓库级别 local 【优先级最高】
2、用户级别 global【优先级次之】
3、系统级别 system【优先级最低】
git
仓库级别对应的
配置
文件是当前仓库下的.
git
/
config
【在当前目录下.
git
目录默认是隐藏的,所以在文件管理器中我们要打开显示以藏文件】
git
用户级别对应的
配置
文件是用户宿主目录下的~/.
git
config
【宿主目录:C:\Users\xiong】
要同步本地存储库和.
git
config
,请使用:
Ubuntu: ln ./
git
-
config
/.
git
config
.
git
config
Windows: mklink .
git
config
./
git
-
config
/.
git
config
Para Vincular El Repositorio Local Con .
git
config
美国:
Ubuntu: ln ./
git
-
config
/.
git
config
.
git
config
Windows: mklink .
git
config
./
git
-
config
/.
git
config
https://
git
-scm.com/下载傻瓜安装
Git
(勾选GUI和bash)
二、
配置
Git
1、在任意位置右键打开
git
的bash命令操作界面
设置
基础
信息
https://
git
ee.com/pro
git
/ 中文版的
Git
命令提示
##开始
Git
的基本
配置
git
config
--global user.name gn
git
config
--global user.email it_everywhere@163.com
git
config
--global http.sslVerify false 关闭加密证书的校验,自己生成的加密证书不要钱但是别人
终端下输入”
git
”,
查看
提示:
usage:
git
[--version] [--help] [-C ] [-c =]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--
git
-dir=] [--work-tree=] [--namespace=]
2.安装
git
3. 如果你希望每次推送代码时都要求输入用户名和密码(例如使用HTTPS协议进行远程操作),可以运行以下命令:
git
config
--global credential.helper cache
运行该命令后,
Git
会在一定时间内记住你的凭证,不再需要每次输入。
4. 如果你希望永久保存你的凭证,可以运行以下命令:
git
config
--global credential.helper store
运行该命令后,
Git
会将你的凭证保存在磁盘上,免去再次输入的麻烦。注意,这种方式下你的凭证会以明文形式保存在磁盘上,所以请确保你的电脑是安全的。
记住,使用明文保存密码存在一定的安全风险,特别是在公共环境中使用。如果你的代码托管服务提供了其他认证方式(如SSH密钥),推荐使用更安全的认证方式。