git:错误:src refspec main 与任何内容都不匹配

nav*_*een 27 git github

我试图通过 VSCode 使用 git,因为我不知道如何在 VSCode 上使用 Git,所以一切都搞砸了。
然后我尝试像往常一样使用CMD(Windows)。我正在学习,以前从未见过这种错误,所以我不知道如何解决这个问题。

但当我尝试推送到主分支时,它显示了这些错误:

error: src refspec main does not match any
error: failed to push some refs to 'myPathToRepo'
Run Code Online (Sandbox Code Playgroud)

我试过:

  • 我尝试使用另一个分支,它工作正常,但我想使用主分支
  • 我什至尝试删除 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'
Run Code Online (Sandbox Code Playgroud)

这是我的第一次提交:

[master (root-commit) 061a06e] first commit
Run Code Online (Sandbox Code Playgroud)

附言。我只有“主”分支。

我运行的命令:

git init
git remote add origin 'pathToMyRepo'
git add -A
git commit -m "first commit"
git push
git push -u origin main
Run Code Online (Sandbox Code Playgroud)

请帮忙。

161*_*903 30

您没有名为 的分支main。你有一个名为 的分支master

使用正确的名称推送:

git push -u origin master
Run Code Online (Sandbox Code Playgroud)

或者将本地分支名称更改为 main 并使用:

git branch -m main
git push -u origin main
Run Code Online (Sandbox Code Playgroud)


Sky*_*Sky 25

只需确保您的文件夹中有需要提交的内容

  1. git初始化
  2. git 远程添加原点'pathToYourRepo'
  3. git 添加 .
  4. git commit -m“第一次提交”
  5. git push -u 起源主要


vin*_*yll 15

就我而言,我只是忘记了第一次提交

解决办法是git commit -am "initial commit"

我希望错误消息更明确