1. 程式人生 > 其它 >Git入門及上傳專案到github中

Git入門及上傳專案到github中

最近需要將課設程式碼上傳到Github上,之前只是用來fork別人的程式碼。

這篇文章寫得是windows下的使用方法。

第一步:建立Github新賬戶

第二步:新建倉庫

第三部:填寫名稱,簡介(可選),勾選Initialize this repository with a README選項,這是自動建立REAMDE.md檔案,省的你再建立。

第四步:安裝Github shell程式,地址:http://windows.github.com/

第五步:開啟Git Shell,輸入以下命令生成金鑰來驗證身份

ssh-keygen -C '[email protected]' -t rsa

連續三個回車之後會在windows當前使用者目錄下生成.ssh資料夾,和linux一樣。

把資料夾下的id_rsa.pub檔案內容全部複製。

然後開啟github賬戶設定,如圖

開啟ssh keys

右上角點選add ssh key

然後在title隨便輸入,key欄貼上剛才的金鑰。

第六步:在Git Shell下輸入命令測試剛才的公鑰是否認證正確。

ssh -T [email protected]

正確結果會顯示:

Warning:Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
  Hi Flowerowl! You've successfully authenticated, but GitHub does not provide shell access.

warning 不用理會。

第七步:clone剛才新建的repository 到本地,輸入命令:

 git clone https://github.com/Flowerowl/stumansys.git

這時會在目錄下生成:

第八步:將想上傳的程式碼目錄拷貝到此資料夾下:

第九步:切換到Git shell 命令列下,輸入命令:

cd stumansys
git init
git add .
git commit -m 'stumansys'
git remote add origin https://github.com/Flowerowl/stumansys.git
git push origin master

如果執行git remote add origin

https://github.com/Flowerowl/stumansys.git

,出現錯誤:

  fatal: remote origin already exists

則執行以下語句:

  git remote rm origin

再往後執行git remote add origin https://github.com/Flowerowl/stumansys.git 即可。

在執行git push origin master時,報錯:

  error:failed to push som refs to.......

則執行以下語句:

  git pull origin master

先把遠端伺服器github上面的檔案拉先來,再push 上去。

最後,你可以去專案頁面查看了~~程式碼上傳成功!

有問題可以在下方留言,大家一起解決~