Git 推送错误 - 无法将某些引用推送到

发布于 01-13 05:59 字数 756 浏览 3 评论 0原文

我正在尝试将代码上传到我在 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)

感谢您阅读我的查询!

I am trying to upload my code onto a repository I created on github but I get an error.
Assuming the URL of the repository is https://github.com/a, how do I go about uploading my code to my remote repository?

I tried the following commands on git bash after navigating INSIDE the folder I want to upload -

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)

Why is this happening and what could I do to push my code to my remote git repo? (I want to learn how to use git via cmd)

Thanks for reading my query!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

來不及說愛妳2025-01-20 05:59:14

请注意,您已经将远程存储库配置为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 配置一个新的远程存储库到当前本地存储库,此远程配置将“指向” 到<网址>以及此的“别名”将是“origin”(或您在 add之间指定的名称)。

在这种情况下=https://github.com/(path).git

有了这个,您可以拥有各种遥控器,并在执行 git push ${repo_name} 时指定

您可以使用 git pull -u ${repo_name} 为 git pull/status 设置“默认”上游

note that you already have an remote repository configured as origin you must remove this configuration or rename then add the correctly repo.

the git command to remove remotes repositories by name is git remote remove ${repo_name}, in your case:

git remote remove origin

the git command to rename remotes repositories is:

git remote rename ${old_repo_name} ${new_repo_name}

then you can add an new remote with the name origin

git remote add origin https://github.com/(path).git

you can assume that the git command git remote add origin https://github.com/(path).git says to git configure an new remote repository into the current local repository, this remote config will "point" to the <URL> and the "alias" of this <URL> will be "origin" (or the name you specify between add and <URL>).

in this case <URL>=https://github.com/(path).git

With this you can have various remotes and specify then when you execute git push ${repo_name}

You can set an "default" upstream for git pull/status with git push -u ${repo_name}

迷路的信2025-01-20 05:59:14

您写道:

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 代替。

You wrote:

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

Your init created a branch called main but you tried to push master, which doesn't exist. Try pushing main instead.

只等公子2025-01-20 05:59:14

我今天遇到了类似的问题。
我想,问题是回购存在,但分支不存在。
在推送到 main 之前尝试添加 gitbranch -M main。

以下是顺序供您参考:

git remote add origin [git url].git
git branch -M main
git push -u origin main

I faced similar problem today.
I guess, the issue is repo exists but not the branch.
Try adding git branch -M main before pushing to main.

Here is the sequence for your reference:

git remote add origin [git url].git
git branch -M main
git push -u origin main
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文