之前配置过服务器的git环境,但对于本地连接github倒是第一次,这里记录方法步骤。
1.安装好git bash后打开,输入
ssh-keygen -t rsa -C 你的git账号邮箱
之后几个输入直接回车,之后若成功,在C:/users/Administrator下会有.ssh的文件夹,文件夹里有id_rsa和id_rsa.pub两个文件,id_rsa是私钥,本地保存;id_rsa.pub是公钥,用于上传。
2.在github的Account-Settings-SSH and GPG keys上,点击new SSH key,title随便写,把刚才id_rsa.pub的内容复制到key上,点击Add SSH key。
3.测试连接。输入
ssh -T git@github.com
若初次设置按提示输入yes,之后会提示授权成功。
4.设置账户名及邮箱。输入
git config --global user.name your_name
git config --global user.email your_email
5.关联远程库。输入
git remote add origin git@github.com:your_account/hello_world.git
若出现fatal: not a git repository (or any of the parent directories): .git,则要初始化本地库
git init
之后可以通过
git push -u origin master
来推送本地最新修改了
6.下载git项目。输入
git clone git@github.com:your_account/hello_world.git
即可。