很多项目有时候放到本地会很不方便,但是可以将其存储到github或者是gitlab上,需要用到时可以直接将其down下来即可。
关键点: 以下执行步骤是基于已经安装好了github和拥有github账号的前提下呀
以下就是将本地项目上传到github的步骤:
1: 首先得有一个github的账号密码,登录进去之后,可以看到以下界面

点击之后的操作步骤如下图标注:



这不就创建好了嘛哈哈哈

远程将要存放项目的仓库就建好了,接下来是要配置公钥:
2. 在桌面打开安装好的 git Bush here, 然后先检查以下本机是否已经存在ssh,检查的指令如下:

要是没有生成,可以执行以下指令生成:
ssh-keygen -t rsa -C “1321216988@qq.com”

生成之后,在文件ssh文件中找到rsa,用文本打开,然后将里边的内容按照以下步骤复制粘贴好:




github配置公钥的任务就完成啦
接下来是将本地的项目传到github远程仓库~~~
首先,我们需要做的是先熟悉以下几个指令,后边要用到:
git init //把这个需要上传的目录文件编程git可以管理的仓库
git add README.md //文件添加到仓库(这次没用到这个)
git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了
git commit -m "提交的提示内容" // 文件提交到仓库
git remote add origin git@github.com:hhphoebe/test.git // 关联远程仓库 (此处的origin后面的一串,是创建好仓库之后生成的一串ssh,咋们也可以用ssh前面的https对应的url,在此处无影响。)
git push -u origin master // 把本地库的所有内容推送到远程仓库上 (注意,git不能管理空目录,必须得有文件)
执行最后一步的时候,
敲一个:yes, 然后回车

建立远程仓库的步骤大概是这样啦~~~
接下来是在本地新建分支的问题(重点。。。如果新建分支不正确,或者是没有关联到远程仓库的分支,会出现push和update报错的情况呀)
首先注意看好自己IDE的右下角的图标

然后我们需要做的是在本地简历远程分支,并且在建立好的远程分支上新建分支到本地,便于在本地修改代码然后提交
git本地给远程仓库创建分支三步法(在项目目录下打开git bush here ):
1. 本地创建分支dev:
git branch dev
2. 下面把本地分支提交到远程仓库:
git push origin dev
3. 查看一下远程仓库有几个分支:
git branch -a
除此之外,在把本地分支提交到远程仓库之后,还需要在这个分支上再建一个本地分支用于修改,把修改的提交到这个远程的dev分支上,这个可以在IDE上直接操作,步骤如下:


确定之后可以看到以下截图

这样大概就完成啦,接下啦就是拉取代码,也非常的简单:
首先找到远程仓库项目的git地址, 例如:

打开自己的IDE,然后根据截图的步骤down下代码:


这不就拉取成功了吗哈哈哈
还有最后的一点是: 拉去了代码之后,记得先在项目的分支上新建本地分支,不然可能会出现错误呀!
网友评论