从远程git存储库克隆后(在bettercodes) 我做了一些改变,承诺 并试图推动:

git push origin master

错误:

错误:不能锁定现有的信息/引用 致命:git-http-push失败

本案例涉及已经存在的存储库。

我之前做的是:

Git配置-global http。sslVerify假 git init Git远程添加[url] git克隆 更改数据 git提交

在'bettercodes'我没有访问git日志。

我用的是Windows。 具体的错误是:

C:\MyWorkStuff\Projects\Ruby\MyProject\>git push origin master
Unable to create branch path https://user:password@git.bettercodes.org/myproject/info/
error: cannot lock existing info/refs
fatal: git-http-push failed

我之前克隆过,然后修改代码并提交。


当前回答

在我的例子中,它与我已经创建的分支名称相连接。

为了解决这个问题,我创建了一个分支,它的名字肯定不应该存在,比如:

git checkout -b some_unknown_branch

然后我清除了所有其他分支(不活动),因为它们只是不必要的垃圾。

git branch | grep -v \* | grep -v master | xargs git branch -D

然后用我想要的名字重命名我的当前分支,比如:

git checkout -m my_desired_branch_name

其他回答

运行命令git update-ref -d refs/heads/origin/branch修复。

作为Visual Studio Code (vscode, Code)(也可能是其他ide)的参考

我必须执行命令:Git: Fetch (Prune)

命令行替代方案应该是:git fetch——prune

然后重新启动整个IDE。

为了给出一些观点,我将引用BitBucket的码头:

What’s the Difference Between Git Prune,Git Fetch --prune, and Git Remote Prune? git remote prune and git fetch --prune do the same thing: delete the refs to branches that don't exist on the remote. This is highly desirable when working in a team workflow in which remote branches are deleted after merge to main. The second command, git fetch --prune will connect to the remote and fetch the latest remote state before pruning. It is essentially a combination of commands: git fetch --all && git remote prune The generic git prune command is entirely different. As discussed in the overview section, git prune will delete locally detached commits.

在我的例子中,它与我已经创建的分支名称相连接。

为了解决这个问题,我创建了一个分支,它的名字肯定不应该存在,比如:

git checkout -b some_unknown_branch

然后我清除了所有其他分支(不活动),因为它们只是不必要的垃圾。

git branch | grep -v \* | grep -v master | xargs git branch -D

然后用我想要的名字重命名我的当前分支,比如:

git checkout -m my_desired_branch_name

我遇到这个问题是因为我所在的分支与上游分支具有类似的名称。例如,上游分支被称为示例分支,我的本地分支被称为示例分支/后端。解决方案是更改我的本地分支机构的名称,如下所示:

git branch -m <new name goes here>

对我来说,这是有效的(不会改变远程):

Git远程删除源文件

因为这个答案似乎对很多人都有帮助,所以我深入研究了一下这里到底发生了什么。这将删除.git/refs/remotes/origin文件夹中对远程分支的引用。

因此,这不会影响您的本地分支,也不会更改任何远程内容,但它会更新您对远程分支的本地引用。在某些情况下,这些引用可能包含Git无法正确处理的数据。