git 配置多个账户
cd ~/.ssh
ssh-keygen -t rsa -C "xxx@qq.com"
#设置文件名,自动生成私钥和公钥(.pub)
Enter file in which to save the key (/c/Users/icecr/.ssh/id_rsa): id_rsa_github
#将ssh key添加到SSH agent中
ssh-add ~/.ssh/id_rsa_github
在github的profile中添加新的公钥,将.ssh目录下对应的id_rsa_github.pub中的内容拷到Key中
在~/.ssh下新增config文件
内容如下
host github.com
Hostname github.com
User icecrea
IdentityFile ~/.ssh/id_rsa_github
host gitlab.com
Hostname gitlab.com
User xxx
IdentityFile ~/.ssh/id_rsa
具体到某个项目下,可以设置该项目的git配,配置信息存储在项目目录下.git/config文件中。
如果有--global全局的配置,全局配置存储在~/.gitconfig
git config user.name icecrea
git config user.email xxxx@qq.com
校验是否能连接,如下提示表示成功
ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Hi icecrea! You've successfully authenticated, but GitHub does not provide shell
access.
关联远程库
git remote add origin git@github.com:icecrea/test.git
忽略部分上传文件
项目目录下手动创建.gitignore文件
# maven ignore
target/
# idea ignore
.idea/
*.ipr
*.iml
*.iws
网友评论