github推送本地项目

github配置ssh key

1、使用Git Bash生成新的ssh key。

  `$ cd ~  #保证当前路径在”~”下`
  `$ ssh-keygen -t rsa -C "[email protected]"  #github注册时自己的邮箱`
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa):   #不填直接回车
Enter passphrase (empty for no passphrase):   #输入密码(可以为空)
Enter same passphrase again:   #再次确认密码(可以为空)
Your identification has been saved in /c/Users/xxxx_000/.ssh/id_rsa.   #生成的密钥
Your public key has been saved in /c/Users/xxxx_000/.ssh/id_rsa.pub.  #生成的公钥
The key fingerprint is:
e3:51:33:xx:xx:xx:xx:xxx:61:28:83:e2:81 [email protected]

终端出现上述内容表示,本机已完成ssh key设置,其存放路径为:c:/Users/xxxx_000/.ssh/下。

2、添加ssh key到github

  • 点击github自己账户的头像->setting->SSH and GPG keys->new SSH key
  • 进入c:/Users/xxxx_000/.ssh/目录下,打开id_rsa.pub文件,全选复制公钥内容。
  • Title自定义,复制id_rsa.pub的公钥内容到key

3、测试ssh keys是否设置成功。

$ ssh -T [email protected]

The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:xx:xx:xx:xx:xx:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes #确认你是否继续联系,输入yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/xxxx_000/.ssh/id_rsa':  #生成ssh kye是密码为空则无此项,若设置有密码则有此项且,输入生成ssh key时设置的密码即可。

出现此句话,说明设置成功。

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

git本地登录:

git config --global user.name "yourname"
git config --global user.email "youremail"

将本地项目push到Github

  • 打开你的项目文件或文件目录
cd Desktop/mask(这是我的项目文件)
  • 初始化git文件
git init
  • 与远程仓库建立连接(在此之前需要你在自己的网页版github上建立仓库)
git remote add origin [email protected]:yourname/yourrepo.git
  • 添加你的文件或文件目录
git add -A(意为将此文件目录下的所有文件添加上)
  • 把要提交的所有修改放到暂存区(Stage)
git commit -m "task"
  • 一次性把暂存区的所有修改提交到分支
git push -u origin master

结语

希望我的文章能够帮助到你,感谢阅读。

你可能感兴趣的:(github推送本地项目)