本地git关联github

由于本地git仓库和github仓库之间的传输是通过SSH加密的,所以需要配置验证信息.

1 查看是否生成过密钥(id_rsa(私钥) /id_rsa.pub(公钥) )

cd ~/.ssh

2 查看并设置用户名和邮箱 

% git config --list
% git config --global user.name "xx"
% git config --global user.email "xx@126.com"

3 生成密钥

% ssh-keygen -t rsa -C "xx@126.com"

4 将xx_ssh_key.pub 添加到github

5 验证(成功)

% ssh -T git@github.com
Hi xx! You've successfully authenticated, but GitHub does not provide shell access.

6 验证(失败)

% ssh -T git@github.com
git@github.com: Permission denied (publickey).

# 关联私钥
% ssh-add "/Users/xxx/.ssh/xx_ssh_key"

7 github 上创建仓库 testRsp

8 本地创建git项目,并推送到github

% mkdir testgit
% echo "# git ceshi" >> README.md
% git init
% git add README.md
% git commit -m "add md file"
% git remote add origin https://github.com/xxx/testRep.git
% git push -u origin master 

完结撒花
通过知识/经验的分享,节省开发者的时间.
原文地址:https://www.cnblogs.com/ysloong/p/14317827.html