【问题标题】:How to fetch all remote branch, "git fetch --all" doesn't work如何获取所有远程分支,“git fetch --all”不起作用
【发布时间】:2015-10-05 08:42:46
【问题描述】:

我已经查看了有关类似问题的其他问题。

但他们似乎说答案是git fetch --all

但在我的情况下,它不起作用。

这就是我为它所做的。

> git branch
* master

> git branch -r
origin/master
origin/A

> git fetch --all
> git branch 
* master        #still not updated

> git fetch origin/A
fatal: 'origin/A' 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.

> git fetch remotes/origin/A
fatal: 'origin/A' 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.

我也试过git pull --all,但结果是一样的。

-------------------编辑-------

> git pull --all
Already up-to-date.

> git branch 
* master              # I think it should show branch A also

> git remote show origin
 HEAD branch: master
 Remote branches:
   A      tracked
   master tracked

-------------------编辑-------

> git pull origin A
 * branch            A       -> FETCH_HEAD
Already up-to-date.

> git branch 
* master                   # I think it should show barnch A also

【问题讨论】:

  • 1.这是git fetch origin A 不是git fetch origin/A。 2. git pull 将执行 fetchmergegit pull --all 应该对所有跟踪的分支执行拉取操作。
  • 从您的编辑看来,它正在工作。有什么问题?
  • @noahnu 我认为git branch 应该显示branch A 以及master

标签: git version-control fetch


【解决方案1】:

git branch 只显示本地分支。 git branch -r 将显示远程分支,正如您亲眼所见。

git branch
*master

git branch -r
origin/master
origin/A

git fetch --all 将更新您在键入 git branch -r 时看到的列表,但不会创建相应的本地分支。

您要做的是检查分支。这将制作远程分支的本地副本并将上游设置为远程。

git checkout -b mylocal origin/A

git branch
master
*mylocal

git branch -r
origin/master
origin/A

mylocal 在这种情况下是origin/A。如果分支不存在,-b 参数将创建分支。您也可以只输入:git checkout A 将自动命名新分支。

【讨论】:

    【解决方案2】:

    我认为您真正需要的是git branch -a 命令。它将显示所有本地和远程分支。这是一个例子:

    # Only show local branches
    $ git branch
    * master
      develop
    
    # Only show remote branches
    $ git branch -r
      origin/HEAD -> origin/master
      origin/master
      origin/develop
      origin/foo
    
    # Show both local and remote branches
    $ git branch -a
    * master
      develop
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/develop
      remotes/origin/foo
    

    您会注意到所有分支都在那里 - 该命令将显示本地和远程分支。

    foo 分支仅在远程退出,我没有本地 foo 分支。要创建本地 foo 分支,我会使用 checkout 命令:

    # Create a local 'foo' branch from the remote one
    $ git checkout foo
    Branch foo set up to track remote branch foo from origin.
    Switched to a new branch 'foo'
    
    # Show both local and remote branches
    $ git branch -a
    * foo
      master
      develop
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/develop
      remotes/origin/foo
    

    这应该可以解释您在本地看到的内容。

    【讨论】:

      【解决方案3】:

      您还需要在本地创建获取的分支:

      git fetch --all && git checkout A
      

      【讨论】:

        猜你喜欢
        • 2014-03-28
        • 2021-03-20
        • 2012-03-21
        • 2011-07-30
        • 1970-01-01
        • 2016-01-09
        相关资源
        最近更新 更多