没有共同的引用和未指定的引用;什么也不做。

75

我有一个本地的 git 项目,希望将其添加到 gitolite 中。显然这很困难,所以我放弃了这个想法。我通过将它添加到 gitolite-admin/conf/gitolite.conf,并提交和推送更改,创建了一个新的 gitolite 存储库。然后我成功地用 git clone git-noah:project-name 克隆了新的存储库。然后我将除 .git 之外的所有文件和文件夹复制到 project-name 文件夹中。我执行了以下操作:

git add -A
git commit -a -m "Moved to new repo."
git push

我收到这个错误信息:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git-noah:project-name'

你想在消息中运行 git config 语句之一。git help config 可以为您解释它们之间的区别。您还可以阅读这个问题获取更多信息。 - Paul Hicks
事实上,这个问题似乎是规范参考。 - Paul Hicks
1
可能是重复的问题:为什么我无法推送到这个裸仓库? - CAMOBAP
7个回答

190

远程仓库(origin)上尚未存在“main”分支。

git push origin main

完成第一次推送后,您可以使用更简单的方法。

git push

编辑:根据最近的趋势,我的回答已更新将“master”替换为“main”。


1
@Enrico,请检查您正在推送的分支名称。随着最近的趋势,“master”一词正在被更改。 - Oliver
1
@Oliver,是的,你说得对。有些人更喜欢用“主”代替“主要”。 - Tanzeel
1
@Tanzeel,是的,在2020年,“main”可能是更合适的选择。我的原始答案是在2014年编写的,早于新分支命名讨论的出现。 - Oliver
1
奇怪,主函数不起作用并给了我refspec错误... 我不得不将其更改为master。这是在一个新的github存储库上。 - stackers

4
如果你遇到以下错误信息:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch.

但没有收到错误信息:

warning: push.default is unset

在尝试运行 git push 前,请确保您已经运行了 git commit


1
git commit 是我的问题。在推送之前忘记提交文件了。 - HumanHickory

0

针对this user在被接受的答案下的评论。

当我使用fast-export从一个hg Mercurial库迁移到一个已经存在但仍为空的GitLab库时,出现了问题。

错误的原因是这个新的GitLab库的空架构已经设置了主分支应该被称为"master"。消息也提示了这一点:Perhaps you should specify a branch such as 'master'.

在你的情况下,你可能有一个迁移工具将分支名称默认切换为main。而在我的情况下,我向fast-export命令添加了参数-M -main来将名称更改为现在更常见的main,这就与已经设置好的GitLab库中所需的master冲突了。

在git-repo文件夹中,我运行了(错误的)命令:

/data/fast-export/hg-fast-export.sh -r /data/hg-repo -A /data/authors --force -M -main

因此,我回到了起点,没有使用 -M -main 再试了一遍: 我删除了 git-repo 文件夹中的 .git 文件夹,再次运行了 git init my_git_repo 命令,然后只是运行了 fast-export 命令,没有使用 -M -main 。 然后一切正常:我可以执行 git checkout HEAD git remote add origin git@gitlab.com:my_project-url.git git branch git push -u origin --all git push -u origin --tags 命令。

0

你的主分支可能是上游分支,需要取消设置。

分支位于主分支上。

你的分支基于“origin/master”,但上游已经不存在了。 (使用git branch --unset-upstream来解决)


0
如果您正在使用git进行镜像,请使用以下命令:

git config remote.backup.mirror true

0
对我来说,我有未提交的文件。
运行 `git status`。
添加所有文件 `git add .`。
运行 `git push`。
然后, `git push origin main` 或者 master。

-4

由于您重新创建了存储库,因此本地和远程存储库的历史记录不同步。因此,Git 不允许您推送此内容。

如果您不担心丢失远程存储库中的内容,您可以强制推送:git push -f


它们绝对共享历史记录!这是 Git 最棒的功能之一,因为你克隆了整个仓库,所以它知道远程仓库中发生的所有事情。 - Oliver

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接