这是我采取的步骤: 1.进入Github,创建一个仓库。 2.进入我的文件夹并运行
git init
,git add . ,< code> git commit -m“first commit” ,< code> git remote add origin my@repository 和git push -u origin master
3.现在我知道我需要创建一个主分支,所以我还运行了git checkout -b main
,成功运行,但是当我运行git push --set-upstream origin main
时,会出现错误:
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'git@github.com:myuser/myrepo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我也运行了git pull
,但它说已经是最新的。
同样在主分支上运行git merge master
,但是它会提示:已经是最新的
,反之亦然,从主分支尝试合并主要分支(只是为了检查),结果也是相同的消息。
还尝试运行git push -u origin main
,但出现错误:
error: src refspec main does not match any
error: failed to push some refs to 'git@github.com:myuser/myrepo.git'
请注意,我也尝试了这些命令的不同顺序,结果都是相同的错误。
我该怎么解决呢?