首页 > 解决方案 > 推入空的 git repo 时“无法推送引用”

问题描述

我正在尝试从 git 项目中获取一个分支并将其放入另一个 git 存储库但是当我这样做并尝试推送时出现此错误

源引用说明符 refs/heads/master 不对应任何引用错误:不可能将引用推送到“原点”

另外我注意到空项目没有分支,即使是主项目。

标签: git

解决方案


如果您已经克隆了第一个项目,并且想要将分支推送到第二个远程存储库(无提交),您可以这样做:

cd /path/to/cloned/first/project
git remote add second https://url/second/empty/repository
git switch <theCorrectBranch>
git push -u second <theCorrectBranch>:main

这将推<theCorrectBranch>送到第二个远程空存储库的主分支。


推荐阅读