github的简单使用(一)

什么是git,什么是github,说概念我真的不懂,我知道这些东西能够用于源代码的管理。

我为什么要学习github,原因很简单,有次我看到一位牛人的博客说:现在的程序员如果还不会掌握github的使用你还算是一名程序员么?

哎,自己确实也不会,既然这样提到了github,我当时就有了一种要学习github的想法,平常也见过不少人用github,比如很著名的的就是cocos2dx 开源项目:https://github.com/cocos2d/cocos2d-x.git.

于是就马上注册了一个github的账号:

里面有方法教如何创建repository,如何fork,如何follow等等,哎这些都感觉挺简单的。

简单就是简单,但是有些概念我很模糊,git到底是什么,github倒是又是什么?我一直很混淆。

这里极力推荐一个关于git的英文网站:

http://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

里面讲得很详细,这里说说git得历史,

As with many great things in life, Git began with a bit of creative destruction and fiery controversy.

The Linux kernel is an open source software project of fairly large scope. For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.

In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked. This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:

  • Speed

  • Simple design

  • Strong support for non-linear development (thousands of parallel branches)

  • Fully distributed

  • Able to handle large projects like the Linux kernel efficiently (speed and data size)

Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities. It’s incredibly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development (See Chapter 3).

其大概得意思是说:当初linux源码管理是用BitKeeper来管理得,后来在2005年的时候,linux开源社区与BitKeeper的商业公司发生了矛盾,导致Linux社区不能够再免费使用了BitKeeper,在这种情形下,就促使Linux社区的开发人员不得不开发自己的工具,这种工具就是git,它具有速度快,设计简洁,完全分布式,能够处理大型的开源项目,类似Linux内核的特点。

而github呢,github是基于git上的也是一个分布式的源代码管理系统,git是github里面的核心,也许描述的不是很正确,但这是我的理解,错的话,别怪我啊,其实我就
很讨厌这些概念上的东西的。
既然git是github的一个核心部分,所以在使用github的时候,不得不学习以下git了,包括git 的命令啦。好了,废话少说,来点实用的:
比如我有个项目叫MM 的小游戏demo,我想把它的源代码放到github上,开源,给别人下载,怎么弄呢?
1、登录github,创建repository创库,比如我的:

Cocos2dxMyMM

2、在mac上打开终端
输入

$ ssh -T git@github.com //检测是否链接上github了

如果出现以下信息就表明已经连接上了

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


首先配置全局用户名和邮箱
git config --global user.name "user name"
git config --global user.email "user email@qq.com"
这里换成自己的

然后cd到你需要提交的源代码目录,比如我的:

cd MM

接着,输入,


git init //初始化git仓库,

接着输入git status,查看状态,比如我的饿项目下有两个文件夹Classes 和 Resources出现下图:



接着将你项目里面的文件添加进来,当然这时候,你添加的文件并不是真正添加到.git里面,而是添加到索引index里面,

这个索引保存的是变化缓存,直到输入提交命令git commit才添加到.git里面。

输入git add * //这里的*表明将全部的文件添加进来

然后我们在查看下状态,输入git status,  如下图:


接着输入:git commit -m "first commit" // 注意这里-m表示添加的注释,不应该位空

这样就将项目下的文件全部添加到了本地.git库,但这并没有提交到远程的git上,所以还需要输入:

remote add gg git@github.com:aiwobiezoukainnn/Cocos2dxMyMM.git

这里的gg随便取

然后我们查看下远程连接地址,

git remote -v


最后一步就是:push一下:


 git push gg master


如果不成功的话,那就先将远程的拉下来下:

git pull gg master


然后再push.

OK, 先到此吧


推荐学习关于git的学习:

http://www.ihref.com/read-16369.html

git官方中文参考手册:

http://git-scm.com/book/zh







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值