第一步
要托管到github,那你就應該要有一個屬于你自己的github帳号,是以你應該先到github.com注冊
打開浏覽器
在位址欄輸入位址:github.com
填寫使用者名、郵箱、密碼
點選Sign up即可簡單地注冊
<a href="http://s2.51cto.com/wyfs02/M01/80/16/wKioL1c3Tg-jR603AACeB8wRrnI778.png" target="_blank"></a>
完成注冊,進入github平台,
點選new repositories ,建立一個新項目(你也可以加入到一個已有的項目)
<a href="http://s2.51cto.com/wyfs02/M00/80/19/wKiom1c3SnPjQIhQAABJjHx8QH0711.png" target="_blank"></a>
Repository name:通常就寫自己自己要建的工程名。
Description:就是你對工程的描述了。
選擇Public。
如果不想其他人下載下傳Initialize this repository with a README可以不用選擇
<a href="http://s5.51cto.com/wyfs02/M02/80/16/wKioL1c3S5Wg1AcnAADmaBpvQSA657.png" target="_blank"></a>
點選 “Create repository”,出現如下圖表示建立完成:
<a href="http://s4.51cto.com/wyfs02/M01/80/19/wKiom1c3TNGT2ytZAAEhG39yt6I608.png" target="_blank"></a>
第二步
1.建立ssh:打開終端檢測是否存在ssh:指令cd ~/.ssh
如果存在,先将已有的ssh備份,或者将建立的ssh生成到另外的目錄下
,如果不存在,通過預設的參數直接生成ssh
ssh-keygen -t rsa -C [email protected](注冊github時的email),公鑰生成過程一直回車
2.在github中添加ssh(如圖示):
登陸github,點選個人頭像選擇Settings-->SSH and GPG Keys--->New SSH key添加ssh
Title:[email protected]
Key:打開你生成的id_rsa.pub檔案,将其中内容拷貝至此。
最後點選Add SSH key儲存
3.打開終端,先測試一下你的帳号跟github連上沒有:ssh -T [email protected] 如果出現如下提示,
表示你連已經連上了.(因為有了第一步,是以不用自己做過多的連接配接github的操作了,另外,
下一次要連接配接github的時候記得打開第一步的工具).
Hi MiracleHe! You've successfully
authenticated, but GitHub does not provide shell access.
按照上面的步驟來就行了(注意記得在終端中輸入時把目錄切換到你要上傳的工程目錄下)。
簡單分析下上面的步驟:
在github上面建立的項目可以按照下面的進行
touch README.md //建立一個記錄送出操作的文檔
git init //初始化本地倉庫
git add README.md //添加
git add 項目包含的檔案
git commit -m "first commit"//送出到要地倉庫,并寫一些注釋
git remote add origin [email protected]:youname/Test.git //連接配接遠端倉庫并建了一個名叫:origin的别名
git push -u origin master //将本地倉庫的東西送出到位址是origin的位址,master分支下,完成。
在使用git對源代碼進行push到gitHub時可能會出錯,資訊如下:
<a href="http://s4.51cto.com/wyfs02/M01/80/19/wKiom1c3SnmgqJdIAAApXwjQ-jA423.png" target="_blank"></a>
解決方法:
git pull --rebase origin master
<a href="http://s1.51cto.com/wyfs02/M01/80/19/wKiom1c3SqKgnvCgAAA87UQRd5k253.png" target="_blank"></a>
此時再執行語句 git push -u origin master即可完成代碼上傳到github
如下圖所示
<a href="http://s3.51cto.com/wyfs02/M02/80/19/wKiom1c3SqXS0Z5HAAApBXhlU60130.png" target="_blank"></a>
檢視已上傳的項目
<a href="http://s5.51cto.com/wyfs02/M00/80/16/wKioL1c3S53QCDR5AAB1l1mUPw4718.png" target="_blank"></a>
本文轉自 jvrmusic520 51CTO部落格,原文連結:http://blog.51cto.com/linuxtech/1773451