本教程結合Github服務端和客戶端完成本地代碼上傳至Github,下面進行詳細講解:html
1.建立Github帳號,這一個步驟應該不用太多解釋,直接上官網進行註冊登陸便可https://github.com/java
2.新建一個repository。如圖,註冊登陸以後能夠找到以下頁面,新建一個repository。git
正確結果會顯示:github
Warning:Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. Hi LEESF! You've successfully authenticated, but GitHub does not provide shell access.
Warning 不用理會shell
4.clone剛纔新建名爲Test的repository 到本地,輸入命令:windows
git clone https://github.com/leesf/Test.git服務器
以後會在本地生成一個以下的目錄結構:ssh
5.把想要上傳的代碼文件夾複製到GitHub下(與.git處於同一目錄下) 如把GitHubTest文件夾(裏面包含了Test.java文件)複製到此目錄中,如圖:ide
6.開始上傳文件測試
在Shell中依次輸入以下命令:
git init
git add Test/GitHubTest git commit -m "GitHubTest" git remote add origin https://github.com/leesf/Test.git git push origin master
若是執行git remote add origin https://github.com/leesf/Test.git 出現錯誤:
fatal: remote origin already exists
則執行如下語句:
git remote rm origin
再次執行git remote add origin https://github.com/leesf/Test.git便可。
在執行git push origin master時,報錯:
error:failed to push som refs to.......
則執行如下語句:
git pull origin master
先把遠程服務器github上面的文件拉先來,再push 上去
這樣整個上傳過程就完成了,如今能夠在GitHub上查看本身上傳的源代碼了。