1. 程式人生 > >git推送遠端時報錯failed to push some refs to 'ssh://xxxxx.com/project.git'

git推送遠端時報錯failed to push some refs to 'ssh://xxxxx.com/project.git'

當需要將本地的已有的專案作為工作區,並新建本地庫來跟蹤工作區的變化,同時需要將本地庫推送到分散式的伺服器上(如:github)上時,需要進行以下操作:

  • 右擊本地資料夾,git bash here
  • 建立本地庫 在彈出的命令列中輸入git init
  • 在github上新建庫,命名為projectA
  • 將本地庫和github上面的遠端庫關聯 git remote add origin [email protected]:username\projectA
  • 將本地庫的內容推送到github上 git push -u origin master

在最後一步,將本地庫的內容推送到github上時報錯,內容為:

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

解決方案:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.