我无法将我的存储库推送到位桶。"failed to push refs"错误



我无法将我的回购推送到比特桶。错误";未能推动裁判";

我检查了错误:未能推送一些裁判,但那里的答案不适用于我,因为它涉及777权限,而我在windows上。

几年前我就用过比特桶和git。比特桶网站的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:UsersUsersourcereposRemindProjRemindProj>git init
Initialized empty Git repository in C:/Users/User/source/repos/RemindProj/RemindProj/.git/
C:UsersUsersourcereposRemindProjRemindProj>git add -A
C:UsersUsersourcereposRemindProjRemindProj>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:UsersUsersourcereposRemindProgRemindProg>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:UsersUsersourcereposRemindProjRemindProj>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:UsersUsersourcereposRemindProgRemindProg>git remote add bitbucket https://gbatha12@bitbucket.org/gbatha12/reminderonlaptopdownst
airs.git
C:UsersUsersourcereposRemindProgRemindProg>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:UsersUsersourcereposRemindProgRemindProg>

因此,该消息说";远程包含本地没有的工作">

但如果我在bitbucket网站上查看回购,我只看到一个.gitignore文件。

我尝试删除远程站点上存在但不在本地的.gitignore文件。

然后做git push bitbucket master,但同样的错误。

我知道错误消息,建议做一个git pull,尽管我有点不愿意,因为我所在的地区有一些早期版本的程序。通常情况下,当我执行pull时,是在本地没有程序的情况下。无论如何,我以前在使用git和bitbucket时从未出现过这种错误。

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

但就我在你的问题中所读到的内容而言,你不希望这个.gitignore文件出现在你的存储库中。因此,删除.gitignore-文件现在是本地的(在git pull之后,您将拥有此.gitignore-文件本地(,而git push则会发生更改。那么您已经删除了.gitignore-文件。

现在,您可以将其他新文件git push发送到远程BitBucket存储库,因为您没有包含本地没有的工作


你也可以做git push -f(-f表示力(。这将通过本地存储库来推送远程存储库。但应谨慎使用。

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

Git错误消息中有一大部分答案:

更新被拒绝,因为远程包含您在本地没有的工作。这通常是由另一个存储库推送到同一个引用引起的。在再次推送之前,您可能需要先集成远程更改(例如"git pull…"(。

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

我有点不愿意,因为我所在的地区有一些早期版本的程序

如果您的本地工作被提交(即使没有推送(,您也不能因为执行git pull而丢失它。根据您的配置,Git将重新建立基础或合并您的工作和来自远程的提交。


或者如果你不在乎遥控器里有什么,你可以使用git push --force-with-lease来";重写";具有本地存储库内容的远程。

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

如果其他任何答案都不适用,请运行git branch检查分支

在我的案例中,我试图将分支main(运行git init时创建的默认分支(推送到分支master

我收到的错误读取:

git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'bitbucket.org:...

为了解决这个问题,我创建了一个新的master分支,将main合并到master中,并从master推送。

***我还删除了用git branch -D main推送到远程的主要分支帖子

最新更新