【问题标题】:How do I add existing remote branch to my locally cloned repository?如何将现有的远程分支添加到本地克隆的存储库?
【发布时间】:2017-05-14 16:57:04
【问题描述】:

我想将此分支添加到我的本地克隆: https://github.com/dmitriz/mithril.js/tree/rewrite

由于某些不清楚的原因,它没有被克隆。

所以我最终得到了没有该分支的本地目录。是否也有任何简单的方法可以克隆此分支?

【问题讨论】:

    标签: git github branch git-branch git-remote


    【解决方案1】:

    我假设您最初克隆的存储库是您的origin

    所以只需执行git fetch origin,它应该会在git branch -a 上弹出 - 之后您可以使用git checkout -b rewrite origin/rewrite 轻松查看它。

    一个可能的解释是,当您最初克隆它时,该分支根本不存在,并且您从未获取所有(新)分支。

    【讨论】:

    • 没有出现,最后一条命令报错:fatal: Cannot update paths and switch to branch 'rewrite' at the same time. Did you intend to checkout 'origin/rewrite' which can not be resolved as commit?
    【解决方案2】:

    你所要做的就是签出这个分支。

    $ git checkout rewrite
    

    Git 将切换到一个新分支,跟踪远程分支。这是您应该收到的消息

    Branch rewrite set up to track remote branch rewrite from origin.
    Switched to a new branch 'rewrite'
    

    【讨论】:

    • 不起作用:$ git checkout rewrite --- error: pathspec 'rewrite' did not match any file(s) known to git.
    • 应该,它对我有用:gist.github.com/Richard-Degenne/…
    • 我怀疑你的 Git 配置有问题,尽管我不知道它是什么。
    • 你说得对,我是用Github客户端克隆的,显然不靠谱。从 CL 克隆后,它就像您描述的那样工作。
    • 我很想看看是什么导致了这种行为。很高兴我的回答有帮助。
    【解决方案3】:

    如果您克隆存储库,则您已经拥有所有分支。您需要做的就是从中创建一个本地分支,因为它是一个分布式 scm。

    git checkout -b rewrite origin/rewrite
    

    您也可以为您的本地分支机构取其他名称,或者拥有多个副本。

    【讨论】:

    • 不起作用:$ git checkout -b rewrite origin/rewritefatal: Cannot update paths and switch to branch 'rewrite' at the same time.Did you intend to checkout 'origin/rewrite' which can not be resolved as commit?
    猜你喜欢
    • 2021-02-16
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    相关资源
    最近更新 更多