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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31445129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:12:04  来源:igfitidea点击:

How to fetch all remote branch, "git fetch --all" doesn't work

gitversion-controlfetch

提问by SangminKim

I have looked through other questions on similar question.

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

But they seem to say the answer is git fetch --all.

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

But in my case, it doesn't work.

但就我而言,它不起作用。

This is what I have done for it.

这就是我为它所做的。

> 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.

And I also tried git pull --allalso but the result is the same.

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

-------------------Edit-------------------

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

> 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

-------------------Edit-------------------

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

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

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

回答by noahnu

git branchonly displays local branches. git branch -rwill display remote branches, as you've seen for yourself.

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

git branch
*master

git branch -r
origin/master
origin/A

git fetch --allwill update the list you see when you type git branch -rbut it will not create the corresponding local branches.

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

What you want to do is checkout the branches. This will make a local copy of the remote branch and set the upstream to the remote.

你想要做的是结帐分支。这将制作远程分支的本地副本并将上游设置为远程。

git checkout -b mylocal origin/A

git branch
master
*mylocal

git branch -r
origin/master
origin/A

mylocalin this case is origin/A. The -bparameter will create the branch if it doesn't exist. You could also just type: git checkout Awill will auto-name the new branch.

mylocal在这种情况下是origin/A-b如果分支不存在,该参数将创建分支。你也可以只输入:git checkout Awill will auto-name the new branch。

回答by Ivan

You need to create the fetched branch locally as well:

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

git fetch --all && git checkout A

回答by nwinkler

I think what you're really looking for is the git branch -acommand. It will show all local and remote branches. Here's an example:

我认为您真正要寻找的是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

You will notice that all of the branches are there - the command will show both local and remote branches.

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

The foobranch only exits on the remote, I don't have a local foobranch. To create a local foobranch, I would use the checkoutcommand:

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

This should explain what you're seeing locally.

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