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 [email protected] //檢測是否鏈接上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 protected]"
這裏換成自己的

然後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 [email protected]: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







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章