我无法将我的回购推送到 bitbucket。 "failed to push refs" 的错误

I can't push my repo to bitbucket. Error of "failed to push refs"

我无法将我的存储库推送到 bitbucket。 “无法推送参考”的错误

我检查了 error: failed to push some refs 但那里的答案不适用于我,因为它说的是 777 权限,而我在 windows.

我在几年前使用过 bitbucket 和 git。 bitbucket 网站的 GUI 也发生了一些变化。过去,当我在 bitbucket 中创建一个 repo 时,bitbucket 会给出一些我可以粘贴的命令,比如 git remote origin... 和一些 URL..(我会使用词 bitbucket 而不是 origin)。但是 bitbucket 的设计已经改变,我现在看不到那些命令,我​​无法让它工作。

(根据我在 youtube 视频中看到的建议),为了找到添加 git“远程”的行,我转到了 GUI 中的克隆选项,没有做任何克隆,我得到 https://gbatha12@bitbucket.org/gbatha12/reminderonlaptopdownstairs.git

的 URL

然后我做了git remote add bitbucket https://gbatha12@bitbucket.org/gbatha12/reminderonlaptopdownstairs.git

如下图所示。

C:\Users\User\source\repos\RemindProj\RemindProj>git init
Initialized empty Git repository in C:/Users/User/source/repos/RemindProj/RemindProj/.git/

C:\Users\User\source\repos\RemindProj\RemindProj>git add -A

C:\Users\User\source\repos\RemindProj\RemindProj>git push bitbucket master
error: src refspec master does not match any
error: failed to push some refs to 'bitbucket'

(ok that's understandable I have to create a commit)

C:\Users\User\source\repos\RemindProg\RemindProg>git commit -m "earlyversion"
[master (root-commit) c8b3dc1] earlyversion
 25 files changed, 596 insertions(+)
 create mode 100644 App.config
 create mode 100644 Form1.Designer.cs
 create mode 100644 Form1.cs
 create mode 100644 Form1.resx
 create mode 100644 Program.cs
 create mode 100644 Properties/AssemblyInfo.cs
 create mode 100644 Properties/Resources.Designer.cs
 create mode 100644 Properties/Resources.resx
 create mode 100644 Properties/Settings.Designer.cs
 create mode 100644 Properties/Settings.settings
 create mode 100644 RemindProj.csproj
 create mode 100644 bin/Debug/RemindProg.exe
 create mode 100644 bin/Debug/RemindProg.exe.config
 create mode 100644 bin/Debug/RemindProg.pdb
 create mode 100644 obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs
 create mode 100644 obj/Debug/DesignTimeResolveAssemblyReferences.cache
 create mode 100644 obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
 create mode 100644 obj/Debug/RemindProg.Form1.resources

C:\Users\User\source\repos\RemindProj\RemindProj>git push bitbucket master
fatal: 'bitbucket' does not appear to be a git repository
fatal: Could not read from remote repository.
 create mode 100644 obj/Debug/RemindProg.Properties.Resources.resources
 create mode 100644 obj/Debug/RemindProg.csproj.CoreCompileInputs.cache
 create mode 100644 obj/Debug/RemindProg.csproj.FileListAbsolute.txt
 create mode 100644 obj/Debug/RemindProg.csproj.GenerateResource.cache
 create mode 100644 obj/Debug/RemindProg.csprojAssemblyReference.cache
 create mode 100644 obj/Debug/RemindProg.exe
 create mode 100644 obj/Debug/RemindProg.pdb

Please make sure you have the correct access rights
and the repository exists.


OK that's understandable I have to add the git "remote".


C:\Users\User\source\repos\RemindProg\RemindProg>git remote add bitbucket https://gbatha12@bitbucket.org/gbatha12/reminderonlaptopdownst
airs.git

C:\Users\User\source\repos\RemindProg\RemindProg>git push bitbucket master
To https://bitbucket.org/gbatha12/reminderonlaptopdownstairs.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://bitbucket.org/gbatha12/reminderonlaptopdownstairs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

C:\Users\User\source\repos\RemindProg\RemindProg>

所以消息说“远程包含您在本地没有的工作。”

但是如果我查看 bitbucket 网站上的 repo,我只会看到一个 .gitignore 文件。

我尝试删除那个 .git忽略存在于远程站点但不存在于本地的文件。

然后执行 git push bitbucket master 但同样的错误。

我知道错误消息,建议执行 git 拉取,但我有点不愿意,因为我所在的地区有我的程序的一些早期版本。通常,当我进行拉取时,是在我本地没有程序的时候。无论如何,我过去在使用 git 和 bitbucket 时从未遇到过这个错误。

您在 Git 错误消息中有很好的答案:

Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.

您首先需要从本地存储库中的远程提取现有提交。例如使用 git pull.

i'm a bit reluctant to because my local area has some early version of my program

如果您的本地工作已提交(即使未推送),您也不会通过 git pull 丢失它。根据您的配置,Git 将变基或合并您的工作和来自远程的提交。


OR 如果您不关心遥控器中的内容,您可以使用 git push --force-with-lease 来“覆盖”遥控器您本地存储库的内容。

注意:如果其他人已经签出您的存储库并开始使用它,请不要这样做。不过你的情况似乎不是这样。

要消除此错误,最好的方法是执行 git pull。然后,您的 BitBucket 存储库中的 .gitignore 文件也在本地。

但据我在你的问题中所读到的,你不希望这个 .gitignore 文件出现在你的存储库中。因此,现在删除本地 .gitignore-文件(在 git pull 之后,您将拥有此 .gitignore-文件本地)并且 git push 此更改。然后你删除了 .gitignore-file.

现在您可以 git push 其他新文件到远程 BitBucket 存储库,因为您没有 contains 工作,您在本地没有 .


您还可以做的是 git push -f (-f for force)。这将 over push 远程存储库与本地存储库。但这应该谨慎使用

注释来自 Barlop/OP。我所做的是做 git push -f 的解决方案。对我来说是安全的,因为它是我自己的个人项目和一个新的回购协议。我没有拉。