git 配置多個賬戶
cd ~/.ssh
ssh-keygen -t rsa -C "xxx@qq.com"
#設(shè)置文件名,自動生成私鑰和公鑰(.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目錄下對應(yīng)的id_rsa_github.pub中的內(nèi)容拷到Key中
在~/.ssh下新增config文件
內(nèi)容如下
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
具體到某個項(xiàng)目下嗜愈,可以設(shè)置該項(xiàng)目的git配行疏,配置信息存儲在項(xiàng)目目錄下.git/config文件中徘键。
如果有--global全局的配置翩瓜,全局配置存儲在~/.gitconfig
git config user.name icecrea
git config user.email xxxx@qq.com
校驗(yàn)是否能連接有咨,如下提示表示成功
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.
關(guān)聯(lián)遠(yuǎn)程庫
git remote add origin git@github.com:icecrea/test.git
忽略部分上傳文件
項(xiàng)目目錄下手動創(chuàng)建.gitignore文件
# maven ignore
target/
# idea ignore
.idea/
*.ipr
*.iml
*.iws