我正在尝试将代码上传到我在 github 上创建的存储库,但出现错误。 假设存储库的 URL 是 https://github.com/a,我该如何将代码上传到远程存储库?
在我要上传的文件夹内导航后,我在 git bash 上尝试了以下命令 -
git init
(output - Reinitializing existing Git repository in C://(path)/.git/
git add.
(blank output)
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git remote add origin https://github.com/(path).git
(output - error: remote origin already exists)
git push origin master
(output - error:src refspec master does not match any
error failed to push some refs to https://github.com/(path).git)
为什么会发生这种情况?我该怎么做才能将代码推送到远程 git 存储库? (我想学习如何通过cmd使用git)
感谢您阅读我的询问!
请注意,您已经将远程存储库配置为
origin
您必须删除此配置或重命名,然后添加正确的存储库。
按名称删除远程存储库的 git 命令是
git remote remove ${repo_name}
,在您的情况下:
git remote remove origin
重命名远程存储库的 git 命令是:
git remote rename ${old_repo_name} ${new_repo_name}
然后您可以添加一个名为 origin 的新遥控器
git remote add origin https://github.com/(path).git
您可以假设 git 命令
git remote add origin https://github.com/(path).git
表示要 git 配置一个新的远程存储库到当前本地存储库中,此远程配置将“指向”add
和 在这种情况下
有了这个,您可以拥有各种遥控器,并在执行时指定
git push ${repo_name}
您可以使用
git push -u ${repo_name}
为 git pull/status 设置“默认”上游
我今天遇到了类似的问题。 我想,问题是回购存在,但分支不存在。 在推送到 main 之前尝试添加“gitbranch -M main”。
以下是顺序供您参考: git 远程添加源 [git url].git git分支-M主 git push -u origin main
你写道:
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git push origin master
(output - error:src refspec master does not match any
您的 init 创建了一个名为 main 的分支,但您尝试推送 master,但该分支不存在。尝试按 main 代替。