config 设置
git config可以用于git的设置,git共有三个不同层级的配置文件,他们作用范围不同,且逐一覆盖上一层
系统级:—system 适用于该系统所有用户,存储位置:/etc/gitconfig
用户级:—global 适用于特定的用户,存储位置:~/.gitconfig
仓库级:—local 适用于某个仓库,存储位置:当前仓库的 .git/config
第一次安装或是想修改用户名和邮件地址时,可以使用如下代码,这个信息主要用于每次提交时识别记录
$ git config --global user.name "gwaslab"
$ git config --global user.email Yunye@gwaslab.com
查看当前设置,以及其存储文件位置:
git config --list --show-origin
Token
简单来说:token就是与github交互时password的替代,安全性更高(但有时也更麻烦)
创建token
在github网站上自己的icon菜单里依次点击即可:
Settings → Developer settings → Personal access token → Generate a personal access token
参考:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
不想频繁输入token的设置
在command line提示输入密码时使用之前的token代替password即可
$ git clone <https://github.com/username/repo.git>
Username: your_username
Password: your_token
为了方便可以,可以将输入的token缓存,使用下面的设定后对目前用户的token输入一次后会缓存:
git config --global credential.helper cache
不需要时可以取消
git config --global --unset credential.helper