代码之家  ›  专栏  ›  技术社区  ›  David Parks

向本地git repo添加远程指向似乎失败

git
  •  0
  • David Parks  · 技术社区  · 6 年前

    我正在关注这篇so文章,将一个repo中的本地分支迁移到一个新repo中的本地分支(我们从github迁移到gitlab)。

    How to merge branches in 2 different repositories?

    一路上我遇到了一个问题。我添加了一个指向旧github本地repo的远程:

    git remote add github-local ~/myprojectdir/src/.git
    

    当我奔跑 git branch -r 在新克隆的gitlab repo中,我希望看到两个分支 github-local (我刚才添加的遥控器),以及 origin . 但我只看到来自起源的分支。

    上面so文章的下一步是创建一个分支和跟踪 github-local/mybranch :

    git checkout -b mybranch --track github-local/mybranch
    

    如果我在运行时在遥控器列表中看不到它,我想我不能这样做 列出远程分支 ?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Egor Laufer    6 年前

    首先检查遥控器是否显示在遥控器列表中。跑 git remote -v . 输出应类似于:

    github-local ~/myprojectdir/src/.git (fetch)
    github-local ~/myprojectdir/src/.git (push)
    origin       repo_url (fetch)
    origin       repo_url (push)
    

    如果 github-local 出现在远程列表中,您只是缺少 git fetch --all .

    在那之后,你应该能够追踪 GITHUB本地 正如你所说的。运行:

    git checkout -b mybranch --track github-local/mybranch
    

    然后通过运行 git branch -vv . 输出应类似于:

    mybranch 068512a [github-local/mybranch] commit_message