Git Config

设置SSH方式

解决操作时候,需要手动输入密码的问题

查看当前origin的URL

1
git remote -v

删除当前origin

1
git remote rm origin

增加origin

1
2
3
4
5
# 例如git remote add origin git@github.com:sulangsss/sulangsss.github.io.source.git
# git remote add origin git@gitee.com:sulang357159/github.pages.git
git remote add origin git@github.com:username/repository.git

git push -u origin master

设置个人信息

1
2
git config --global user.name "user_name"
git config --global user.email "user_email"

生成ssh的key

1
ssh-keygen -t rsa -C "youremail@example.com"

用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,
id_rsa.pub是公钥,可以放心地告诉任何人。

Add Private Key

1
2
3
ssh-add -K ~/.ssh/id_rsa.pub

ssh -T git@github.com

SSH 443

~/.ssh/config

1
2
3
Host github.com
Hostname ssh.github.com
Port 443

Changing Your Committer Name & Email

1
2
3
4
5
6
7
# Global
git config --global user.name "John Doe"
git config --global user.email "john@doe.org"

# per Repository
git config user.name "John Doe"
git config user.email "john@doe.org"

多个Public管理

~/.ssh/config

1
2
3
4
5
6
7
8
9
10
#   Bob github account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Alice github account
Host github.com.alice
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_alice

举例:git clone git@github.com:myproject/email.git,此时默认使用~/.ssh/id_rsa,如果修改为git@github.com.alice:myproject/email.git,则使用~/.ssh/id_rsa_alice