git分布式版本控制系统
我第一个接触的版本控制系统是svn,当时觉得版本控制就是这样,直到我遇到了git...
git是分布式版本控制系统,合适分布式开发,强调个体。速度快、灵活,代码冲突了也比较好解决,最让我喜欢的还是git的分支切换。
在github上创建一个空项目
我这里git的远程仓库选择github,github是全球最大的代码托管库,在国内也有许多类似的站点可以选用(比如:coding)。
-
这里假定已经有了github账号。登录github点击右上角的加号,选择new repository选项新建一个项目。
新建项目
-
填写新项目的基本信息:
新的项目名称,描述,其他默认,然后点击create repository按钮新建项目
填写新项目基本信息
-
克隆新项目至本地
点击README按钮,去编辑README文件。
新建README文件
写下hello world,然后到页面最下方点击commit new file按钮。
hello world
点击use https 然后点复制按钮
复制
去你的本地文件夹,打开git bash。输入命令
git clone <刚才复制的项目地址>

如果还没安装git,可以自行百度下载git,安装无脑,一路下一步就好。
到此为止,新的项目就好了。

提交 (commit)
进入新建的项目文件夹,就可以开始你的代码了。

这里为了方便,假定已经在项目里写了一段代码。准备提交至远端代码仓库。进入项目文件夹,输入命令:
git status

添加更改的代码
git add .

提交代码
git commit -m "提交代码"

log命令可以查看提交历史
git log

推送提交至远程分支push
git push origin master

至此就完成了git的首次提交

补充
这里使用的bash是git(戳这里下载)自带的,如果觉得打命令搞不懂,可以试试图形化界面(例如:sourcetree)
网友评论