【问题标题】:Git Error : 'upstream' does not appear to be a git repositoryGit 错误:“上游”似乎不是 git 存储库
【发布时间】:2015-12-30 23:17:19
【问题描述】:

我对 Git 很陌生,因此在正确使用它时遇到了一些问题。 这是我的场景。

我有一个主存储库的分支并将其克隆到我的本地。 在那,我有 2 个分支用于不同的修复。

当我提交时,我在 git 中看到了一条语句——我们说我提前 3 次提交,落后大约 20 次提交。

我了解我的 fork 与 master 不同步。我也需要合并这两个分支(或者我应该这样做吗?)

我使用 windows 客户端进行同步。但似乎我没有遵循 Git 的方式。所以,我尝试按照https://help.github.com/articles/syncing-a-fork/ 中描述的步骤操作,这给了我如下错误(我正在使用 Windows)。

 $>git fetch upstream
 fatal: 'upstream' does not appear to be a git repository
 fatal: Could not read from remote repository.

 Please make sure you have the correct access rights
 and the repository exists.

我有点困惑。 请帮助我完成在这种情况下应该遵循的步骤。

@HuStmpHrrr

很抱歉在 cmets 中添加了详细信息 为了便于阅读,我将修改问题

通过执行命令:

  $>git remote  returning two values
  acme-development (which the name of my actual/main repository, from where I forked) and
  origin

添加更多信息。


获取后,我尝试将源/主合并到我的主 请看截图

但是,如果我登录到我的 Github 在线帐户,那就是另一回事了。

我的 git 客户端说 本地 repo 是最新的。 但是网上的 git 说我们落后了 42 个提交,提前了 7 个提交。

【问题讨论】:

  • 你是怎么clone的?我猜你的意思是git fetch origin。如果您定义了上游,则单独使用 git fetch 即可。或者大多数人实际上更喜欢git pull
  • 我认为您需要向我们展示git remote
  • $>git remote acme-development 起源
  • 不要将其粘贴在评论中,而是粘贴在您的问题中。所以你有两个遥控器,acme-developmentorigin。我敢打赌它是origin。改为git fetch origin

标签: git github


【解决方案1】:

所以有几点需要澄清:

  • 上游 是存在的远程存储库(或多个存储库)的概念名称。大多数项目只有一个上游存储库。

  • 上游存储库的名称可能因项目而异,但按照惯例是origin

也就是说,我敢打赌,您对上游 repo 的名称和上游 repo 概念感到困惑,您应该执行 git fetch origin。使用git remote 进行验证;使用该列表中的适当名称。

但是,如果您只有一个上游 repo,执行 git fetch 将完成同样的事情。

【讨论】:

    【解决方案2】:

    您链接到的文章(尽管在您询问后可能已更改)以引用 https://help.github.com/articles/configuring-a-remote-for-a-fork/ 开头。如果您完成此操作,您将拥有一个名为 upstream 的新远程存储库,指向您分叉的原始存储库,git fetch upstream 将起作用。

    【讨论】:

    • 文章中唯一需要的命令是git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git,你可以在上面的命令之后继续git fetch upstream
    • @NgSekLong 谢谢,这有助于解决upstream 问题
    【解决方案3】:

    这是我今天解决相同问题所遵循的步骤

    以下步骤将使您能够链接您的 git fork 和原始存储库,以便您可以在原始存储库更新时随时从原始存储库中提取更改。 转到 github 上的存储库页面并单击 fork(如果您还没有这样做)。假设您从https://github.com/account/repo-name 分叉了一个名为 repo-name 的存储库,那么您会在自己的帐户上以https://github.com/your-user-name/repo-name 之类的方式获得该存储库的副本(分叉)然后在您的终端上运行以下命令

    • git clone https://github.com/your-user-name/repo-name.git
      
    • cd repo-name
      
    • git remote add upstream https://github.com/account/repo-name.git
      
    • git pull upstream master
      
    • git branch --set-up-stream-to=upstream/master
      
    • git pull
      

    当您进行更改并希望将其集成到原始代码库中时,为了将您的更改添加到原始存储库,您必须先在 github 上推送到您的 fork 并发送拉取请求,然后将验证并合并到代码库。下面的步骤。

    • git add .
      
    • git commit -m "commit message"
      
    • git push origin master
      

    然后访问您在 github 上的帐户并点击您的 repo-name。在页面上,您将看到创建拉取请求的链接。单击链接并创建拉取请求,然后由维护者审查和合并。

    【讨论】:

      【解决方案4】:

      你必须得到一个 git 项目的 fork 那么:

      git远程添加上游https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

      你可以继续 git fetch 上游

      【讨论】:

        【解决方案5】:

        只需在终端上运行以下命令

        $ git remote add upstream {your upstream repository link here}

        此命令运行后:

        git remote -v

        此命令将显示您的 github 存储库路径和上游存储库路径。

        示例输出:

        origin  https://github.com/ {Your Github username} / {repository name} (fetch)
        origin  https://github.com/ {Your Github username} / {repository name} (push)
        
        upstream    https://github.com/ {Upstream github username} / {repository name} (fetch)
        upstream    https://github.com/ {Upstream github username} / {repository name} (push)

        【讨论】:

          猜你喜欢
          • 2013-03-04
          • 1970-01-01
          • 2021-07-28
          • 2017-01-26
          • 2013-08-26
          • 1970-01-01
          • 1970-01-01
          • 2015-07-01
          相关资源
          最近更新 更多