上傳項目到gitHub
創建好后開始提交本地項目代碼如圖:
選中VCS選中圖中的按鈕如圖所示:
然后再選中Src點中add按鈕如圖所示:

然后點中commit Directory后
打開終端進行項目根目錄下鍵入以下 命令:
git remote add origin git@github.com:codegeekgao/Test.git(這里我寫的自己的github地址,這里可以改成你自己的github項目)
git push -u origin master //將本地倉庫的東西提交到地址是origin的地址,master分支下
可能出現的報錯異常
出現錯誤 error:src refspec master does not match any
引起該錯誤的原因是目錄中沒有文件,空目錄是不能提交上去的.
解決辦法:
在項目根目錄下,創建README.md 文件即可
$ touch README.md
$ git add README,md
$ git commit –m’first commit’
$ git push origin master
進一步可能再次出現Permission denied (publickey). fatal: Could not read from remote repository.
這是因為本地沒有ssh的密鑰,生成密鑰,在GitHub上添加這個ssh密鑰即可,操作步驟如下:
1.首先,如果你沒有ssh key的話,在ternimal下輸入命令:ssh-keygen -t rsa -C "youremail@example.com", youremail@example.com改為自己的郵箱即可,途中會讓你輸入密碼啥的,不需要管,一路回車即可,會生成你的ssh key。(如果重新生成的話會覆蓋之前的ssh key。)
2. 若是window操作系統,會在C盤的用戶目錄下創建一個ssh目錄,同理ios系統也是在用戶目錄下有ssh目錄。
用文本編輯器打開id_rsa.pub,復制里面的內容添加到github,如下圖所示:
添加之后驗證SSH的密鑰
提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.即為成功
提示出錯信息:fatal: remote origin already exists. 解決辦法如下:
然后再次輸入git remote add origin git@github.com:codegeekgao/Test.git
git push -u origin master
然后會報以下錯誤:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:qzmly100/repository-.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
這是因為:
遠程分支上存在本地分支中不存在的提交,往往是多人協作開發過程中遇到的問題,可以先fetch再merge,也就是pull,把遠程分支上的提交合並到本地分支之后再push。
如果你確定遠程分支上那些提交都不需要了,那么直接git push origin master -f,強行讓本地分支覆蓋遠程分支.