使用github管理你的代碼
關於為什麼使用github,網上已經有很多討論了。當然選擇還有google code, Bitbucket,sourceforge。github有如下優勢:
1. github更有利於開源項目的發展
source forge並沒有充分體現這一點,它更像一個開源軟件下載站。至於Google Code,這是個傳奇。但是已經被新CEO布林頒布的大掃除政策打死了,屬於邊緣化業務,Google不會投入新精力了,隻是礙於原本有很多項目依舊運行在Google Code上,所以才沒有像Google Reader一樣徹底關閉。但是基本上活躍用戶都遷走了。
在github上使用開源項目的流程是:
a. 下載,可以直接下載或者git clone下來,可以下載當前版本也可以下載某個分支,或者某個tag,甚至是某個commit
b. 使用(這個跟sf差不多了)
c. 修改,直接fork一個就可以改了,改完可以給作者發個pull request,這樣才能讓開源項目不斷的完善起來
github 讓這一切都變得簡單,直接;不像很久以前的開源界,想要貢獻點代碼,你還得先進mail list,先幫著解答,時機成熟了再讓你改點bug
2. github更方便溝通
任何人可以給項目創建issue, 寫上特性需求或者報告bug,作者或項目成員會很快做出回應
在 sf上,作者和項目成員都不知道在哪,隻有在版本發布的時候會在上麵更新一下
3. github引入了社交元素
github 上的用戶是可以follow別人的,也可以watch某個項目
這很重要,可以每天都多了解一點點,每天多進步一點點
唯一不足的地方就是沒有像twitter那樣,有人follow會發一封email通知下,讓你看看是不是要回fo
4. github更開放
github提供眾多的api,可以跟多數管理服務整合
網站上有大量的幫助文檔,從 git的入門到github的使用都有,非常詳細、圖文並茂
官方博客經常發布一些技術文章,內容涉及故障處理過程,性能優化,各種技術解決方案的選擇思路
此外,可以為項目創建靜態網站,並且沒有任何的限製,無廣告
這個功能被很多人用於托管博客,我的博客就是建在這上麵,免費
5. github還在快速發展
從最初github發展時隻具備基本的源代碼托管功能,到速度的提升(遷至rackspace使國內用戶訪問飛快),到gist的推出,到wiki的版本化,到pull request的出現。
因為還有一大群不明真相的群眾紮根在sf,還不知道github或者還不了解 github有多優秀他們會覺得sourceforge已經非常好了,足夠使用,直到有一天,他們真正被github的魅力所吸引所以,我們在很長的一段時間內都會看到,知名項目一個接一個地慢慢往github上移最終,sf的創始人會說:媽的,老子也移過去算了。以上內容轉自https://www.cnblogs.com/draem0507/articles/2151162.html。知乎上也有很精彩的討論:GitHub、Bitbucket、Google
Code 各有哪些優缺點?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
如何使用github?
首先去github.com注冊賬號。windows的客戶端我用的是官方的:https://windows.github.com/。當然據說msysgit+TortoiseGit也不錯。官方有個15分鍾的training不錯:https://try.github.com/。Refer to https://training.github.com/ for more trainings.
關於配置,因為git默認采用的https協議,每次的pull(get from git server)/push(upload the local copies to git server)都需要輸入密碼,因此可以使用ssh key的方式去認證。方法如下:打開Git Shell在其中輸入如下命令:ssh-genkey -t rsa -C "email@address"。之後會讓你選擇是否對存放SSH
Key的文件夾進行加密,選擇默認值就可以了。在用戶的目錄下的有新生成的.ssh 文件夾,複製 id_rsa.pub文件內容,設置到github賬戶中:登陸你的GitHub賬戶,依次點擊Account Settings >SSH Public Keys >
Add another public key,把id_rsa.pub中的內容拷貝進去 。使用ssh -T git@github.com可以驗證設置是否正確:
接下來要使用git shell 設置賬號信息:
首先,git要求使用者必須提供自己的身份標識,為此我們需要在git bash中執行以下命令:
git config --global user.name 'anzhsoft' git config --global user.email anzhsoft@gmail.com
接下來可以將本地的project上傳到githcd Project_pathgit init ##在當前目錄下生成一個隱藏目錄(.git),這個目錄就是git用來管理軟件版本的倉庫。
cd project_path ## 1 initialize the project git init ##it will generate the dir .git under the project_path, which is used to manage the current repository ## 2 connect the remote git server git remote add origin git@github.com:anzhsoft/repository.git ## 3 add the items git add . ## 4 commit git commit -m "initial commit" ## 5 push to server git push -u origin master
常見錯誤可以見 https://blog.csdn.net/dengjianqiang2011/article/details/9260435
如果你在create repository時添加了readme,license等文件,那麼##5會出現一些錯誤:
To git@github.com:anzhsoft/Readings.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:anzhsoft/Readings.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushin hint: to the same ref. You may want to first merge the remote changes (e.g. hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.直接force這個push就可以了:
git push -f origin master
最後廣告貼: welcome to https://github.com/anzhsoft
最後更新:2017-04-03 12:54:03