第一次將本地項目push到github


問題:github有一個空項目,將本地項目上傳到github空項目時,報錯如下

$ git push --set-upstream git@github.com:dslu7733/promise.git master
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:dslu7733/promise.git'

解決辦法

1. 賬戶問題

我的本地以前配置過2個github賬戶的SSH,可以在用戶(eg. user/username)文件夾下查看.ssh文件夾。這是windows系統生成ssh密匙的默認路徑,里面有3個比較重要的文件:config dslu7733_rsa dslu7733_rsa.pub
(這里的dslu7733是我github的賬號名,其中dslu7733_rsa和dslu7733_rsa.pub是與ssh密匙相關,主要看config的內容)

config決定了本地主機如何解析域名

Host github-dslu
HostName github.com
User git
IdentityFile ~/.ssh/dslu7733_rsa

可以看到,本地域名github-dslu(Host)解析為github.com, 同時本地用戶為git, IdentityFile指明ssh密匙所在路徑。

2. pull

當然本地需要先git add.git commit

$ git pull -f git@github-dslu:dslu7733/promise.git master --allow-unrelated-histories

這里我就把git@github.com:dslu7733/promise.git改為了git@github-dslu:dslu7733/promise.git, 當然本地只配置了一個SSH賬戶的不需要改

由於第一次pull,2個項目不相干(unrelated-histories),所有需要命令--allow-unrelated-histories

3. push

git push --set-upstream git@github-dslu:dslu7733/promise.git master

最后因為第一次push, 需要命令--set-upstream


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM