从git上传到github仓库

本文快速上手git上传代码到远程仓库。
*

1.初始化本地库

新建一个文件夹。在没有初始化本地库前,文件夹是这样的。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190412192548165.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNDc2NzMx,size_16,color_FFFFFF,t_70)
初始化一下本地库:打开git窗口:
输入`git init`初始化仓库
输入`git  config --global user.name "你在github上的用户名" `
输入`git config  -- global user.email "你在github上的邮箱地址"`
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190412193218266.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNDc2NzMx,size_16,color_FFFFFF,t_70)
***

2.创建远程版本库


1)创建 SSH Key
	$ ssh-keygen -t rsa -C "your email"
	在用户主目录里找到.ssh 目录,里面有 id_rsa 和 id_rsa.pub
2)登陆 GitHub,打开“Account settings”,“SSH Keys”页面。点“Add SSH Key”, 填上任意 Title,在 Key 文本框里粘贴 id_rsa.pub 文件的内容。点“Add Key”,你就应该看到已经添加的 Key,插入id_rsa.pub
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190412193810469.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyNDc2NzMx,size_16,color_FFFFFF,t_70)
3)验证是否成功
	$ ssh -T [email protected]	
	如果出现 Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.说明你成功了

3.添加远程库

先创建一个文件,然后git去add一下再commit提交一下
在这里插入图片描述
注意一定要再提交的时候加上提交的版本注释号。
1)登陆 GitHub,在右上角找到“Create a new repo”按钮,创建一个新的仓库
2)在 Repository name 填入 learngit,其他保持默认设置,点击“Create repository”按钮,就成功地创建了一个新的 Git 仓库
在这里插入图片描述
3)$ git remote add origin git@github:,添加远程库, 名字叫做 origin
4)$ git push -u origin master,把本地库推送到远程库上。由于远程库是空的,我们第一次推送 master 分支时,加上了-u 参数,Git 不但会把本地的 master 分支内容推送的远程新的 master 分支,还会把本地的 master 分支和远程的 master 分支关联起来,在以后的推送或者拉取时就可以简化命令

在这里插入图片描述
说明上传成功了打开github仓库看一下。
在这里插入图片描述
上传成功到仓库。

猜你喜欢

转载自blog.csdn.net/qq_42476731/article/details/89253708