Git/Github 學習

http://www.linuxidc.com/Linux/2011-04/35036.htm
1. GIT


相比CVS/SVN,Git 的優勢:
- 支持離線開發,離線Repository
- 強大的分支功能,適合多個獨立開發者協作
- 速度塊


中文版Git使用指南 點擊這裏。


2. GitHub


GitHub是一個託管Git (開源或閉源)項目的網站,閉源收費,最低7$/月起,免費的300G空間。


使用GitHub步驟:
1、申請GitHub帳戶 xxx ,創建名爲new-project的新Repository 


2、安裝Git客戶端(Linux)
#yum install git git-gui


3、 生成密鑰對,這樣項目可以push到 GitHub上
#ssh-keygen -t rsa -C "[email protected]"
4、將.ssh/id_rsa.pub拷貝到GitHub網站




5、爲了方便,設置ssh不輸入口令
# eval `ssh-agent`
# ssh-add
(輸入passphrase)


6、測試是否能聯通GitHub
#ssh [email protected]
如果配置正確,顯示
ERROR: Hi xxx! You've successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.


7、設置Git全局用戶配置
# git config --global user.name "xxx"
# git config --global user.email [email protected]


8、創建本地新項目工作樹
# mkdir new-project
# cd new-project
# git init
# touch README
# git add README
# git commit -m 'first commit'
定義遠程服務器別名origin
#  git remote add origin [email protected]:xxx/new-project.git   
本地和遠程合併,本地默認分支爲master
# git push origin master  


GitHub網站上就可以看見了, http://github.com/xxx/new-project


9. 更新文件
# vi README
自動commit更改文件
# git commit -a     
更新至遠程
# git push origin master


10. 創建和合並分支
#git branch 顯示當前分支是master
#git branch new-feature  創建分支
# git checkout new-feature 切換到新分支
# vi page_cache.inc.php
# git add page_cache.inc.php
Commit 到本地GIT
# git commit -a -m "added initial version of page cache"
合併到遠程服務器
# git push origin new-feature


如果new-feature分支成熟了,覺得有必要合併進master
#git checkout master
#git merge new-feature
#git branch
#git push 
則master中也合併了new-feature 的代碼


再登錄到GitHub可以看見"Switch Branches"下的分支選項:


GitHub還有一個很實用的功能,查看開發進程網絡圖(Network):


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