我試圖通過 VSCode 使用 git,因為我不知道如何在 VSCode 上使用 Git,所以它把一切都搞砸了。
然后我嘗試像往常一樣使用 CMD (Windows)。我正在學習中,以前從未見過這種錯誤,所以我不知道如何解決這個問題。
但是當我嘗試推送到主分支時它顯示了這些錯誤:
error: src refspec main does not match any
error: failed to push some refs to 'myPathToRepo'
我試過:
- 我嘗試了另一個分支,它作業正常,但我想使用主分支
- 我什至嘗試洗掉 git 檔案夾并再次啟動它
我在 StackOverflow 上看過其他帖子,他們大多說“先提交然后推送,因為當你推送而不提交時會出現這個錯誤”。
洗掉.git/檔案夾并重新啟動后,它開始顯示相同的錯誤
>git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
>git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'myPathToRepo'
這是我的第一次提交:
[master (root-commit) 061a06e] first commit
附注。我只有“主要”分支。
我運行的命令:
git init
git remote add origin 'pathToMyRepo'
git add -A
git commit -m "first commit"
git push
git push -u origin main
請幫忙。
uj5u.com熱心網友回復:
您沒有名為main. 您有一個名為master.
使用正確的名稱推送:
git push -u origin master
或者將您的本地分支名稱更改為 main 并使用它:
git branch -m main
git push -u origin main
uj5u.com熱心網友回復:
確保在設定后啟動 VSCode :
git config --global init.defaultbranch main
這樣,當您初始化新存盤庫并使用 VSCode 進行第一次提交時,您創建的默認本地分支將確實是main,而不是master。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/372631.html
