【问题标题】:Added an existing project to github and got a "* [new branch] master -> master"将现有项目添加到 github 并获得“* [新分支] master -> master”
【发布时间】:2021-03-01 06:41:57
【问题描述】:

按照说明 here 将现有的 project 添加到 github。我做了一个git push origin master 并得到:* [new branch] master -> master

我不记得以前见过这个。这正常吗?

编辑 1:

ray@rays8350 /cygdrive/d/ray/allEclipseProjects/eclipseworkspaces
$ git remote show origin
* remote origin
  Fetch URL: https://github.com/rtayek/eclipseworkspaces.git
  Push  URL: https://github.com/rtayek/eclipseworkspaces.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

ray@rays8350 /cygdrive/d/ray/allEclipseProjects/eclipseworkspaces
$ git remote -vv
origin  https://github.com/rtayek/eclipseworkspaces.git (fetch)
origin  https://github.com/rtayek/eclipseworkspaces.git (push)

ray@rays8350 /cygdrive/d/ray/allEclipseProjects/eclipseworkspaces
$ git branch -vv
* master 8112d8f added license.

ray@rays8350 /cygdrive/d/ray/allEclipseProjects/eclipseworkspaces
$ git branch -a
* master
  remotes/origin/master

ray@rays8350 /cygdrive/d/ray/allEclipseProjects/eclipseworkspaces
$

【问题讨论】:

  • 是的,我认为这很正常。 git statusgit remote -vvgit branch -vv 说什么?
  • git show remote origin 再试试看 evrying 没问题
  • 请参阅编辑 1。

标签: git github git-remote


【解决方案1】:

是的,这很正常。

更准确地说,当 other Git 存储库(在本例中为 GitHub 上的那个)没有您刚刚告诉它创建的分支名称时,这是正常的。它现在已经取得了分支名称。由于您将 GitHub 存储库创建为 完全空 存储库,其中没有提交和分支名称,因此该存储库不可能有您告诉它使用的分支名称。所以它不得不将它创建为一个新的分支名称。

请注意,在任何 Git 存储库中,Git 本身都必须遵守严格的约束:该存储库中的每个分支名称都必须包含某个有效的现有提交的(单个)哈希 ID。这意味着一个新的空存储库不能有任何分支名称,因为它没有提交。出于这个原因,GitHub 提议创建每个新存储库,其中包含一个初始提交,该初始提交包含一个README 文件、一个LICENSE 文件,等等。 The instructions you linked 告诉你避免这种情况,这样一开始的提交就不会妨碍你。

通过避免初始提交,您可以避免这种头痛(处理初始提交),而这会让您感到另一种头痛:没有分支的存储库。但是说明继续告诉您如何使该空存储库变为非空,以便它现在可以具有分支名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 2021-12-29
    • 2020-12-03
    • 2015-01-27
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    相关资源
    最近更新 更多