1.基础配置
查看配置信息:git config [–system |global | local] --list
设置用户名:git config [–system |global | local] user.name [yourname]
设置用户邮箱:git config [–system |global | local] user.email [youremail@xxx.com]
设置git命令别名:git config [–system |global | local] alias.[newCommand] [originalComman]
git的配置文件优先级 local > global > system
–local :位于git项目目录中的.git/config , 只对特定git项目有效
–global :位于C:/Users/Administrator/.gitconfig , 只对当前电脑登录用户有效
–system :位于 git的安装目录 /etc/gitconfig , 对系统所有用户和所有项目有效
2.忽略文件(.gitignore)
在Git工作区的根目录下创建.gitignore文件,按照一定的语法规则填写需要忽略的文件
语法规则如下:
注释:以’#'开始的行,被视为注释
忽略所有指定文件及目录:sample
忽略当前文件及目录:/dir
忽略目录:dir/
不忽略特定文件及目录:!sample
忽略文件及目录(通配符):
*.dex忽略所有以.dex结尾的文件;
*.[oa]忽略所有以.a和.o结尾的文件
3.Git https 免密
git config --global credential.helper store
配置后只需输入一次账号密码
4.生成ssh key
cd ~/.ssh
(window中 ~/ 路径为C:\Users\Administrator)
ssh-keygen -t rsa -f “文件名” -C “备注”
执行完上一条命令后更具提示按两次Enter键
执行完后,在~/.ssh 文件夹中会生成两个文件
如果没有指定文件名的话,生成的文件将是 id_rsa 和 id_rsa.pub
其中,.pub文件为公钥文件,另一个为私钥文件
5.管理多个ssh key
在~/.ssh 目录下创建 config文件
编辑config文件,填写以下格式的内容,本文以GitLab和GitHub为例:
#gitLab
Host gitlab.com
Port 22
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_gitLab_rsa
#gitHub
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_gitHub_rsa