# 远程仓库的账号绑定

1
2
3
4
5
6
7
8
9
10
11
#进入.ssh目录
cd ~/.ssh
#创建密钥对
ssh-keygen -t ras -C "[email protected]"

#example
#创建github的ras公钥
ssh-keygen -t rsa -C "[email protected]" -f "github_id_rsa"
#创建gitee的ras公钥
ssh-keygen -t rsa -C "[email protected]" -f "gitee_id_rsa"

将在~/.ssh 里生成对应的.pub 文件里的内容复制到个人 ssh 公钥中即可

测试是否成功

1
2
ssh -T [email protected]
#ssh -T [email protected]

首次连接会询问你是否要信任该主机,同意即可

1
2
3
4
5
6
7
The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

yes

Warning: Permanently added 'gitee.com,212.64.63.215' (ECDSA) to the list of known hosts.

成功则会返回

1
Hi xxx! You've successfully authenticated, but GITHUB.COM does not provide shell access.

# 设置本地身份

1
2
git config --global user.name "yourname"
git config --global user.email "[email protected]"

设置完之后可以使用

1
git config -l

来查看当前配置信息

# 添加远程仓库

首先在远程仓库中添加新的仓库,cd 到项目文件夹

1
2
3
4
5
6
7
#初始化
git init
#添加当前目录中的文件
git add .
#提交项目
git commit -m "message"

连接到远程仓库

1
2
3
4
5
6
7
8
9
10
git remote add [shortname] [url]

#example
git remote add origin [email protected]:Cerber2ol8/repo.git

#提交项目到远程仓库分支
git push -u [shortname] [branch]
#example
git push -u origin master

* 注意
github 现在默认主分支名是 main,而不是 master(有奴隶主的意思),自欺欺人了属于是