如何获取所有远程分支,“git fetch --all”不起作用

时间:2015-07-16 03:56:37

标签: git version-control fetch

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

但他们似乎说答案是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,但结果是一样的。

-------------------编辑------------------- < / p>

> 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

-------------------编辑------------------- < / p>

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

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

3 个答案:

答案 0 :(得分:9)

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
在这种情况下,

mylocalorigin/A-b参数将在创建后切换到新分支。您也可以输入:git checkout A将自动命名新分支。

答案 1 :(得分:1)

我认为你真正想要的是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

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

答案 2 :(得分:0)

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

git fetch --all && git checkout A