如何获取所有远程分支,“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
How to fetch all remote branch, "git fetch --all" doesn't work
提问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 --all
also 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 branch
only displays local branches.
git branch -r
will 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 --all
will update the list you see when you type git branch -r
but 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
mylocal
in this case is origin/A
. The -b
parameter will create the branch if it doesn't exist. You could also just type: git checkout A
will will auto-name the new branch.
mylocal
在这种情况下是origin/A
。-b
如果分支不存在,该参数将创建分支。你也可以只输入:git checkout A
will 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 -a
command. 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 foo
branch only exits on the remote, I don't have a local foo
branch. To create a local foo
branch, I would use the checkout
command:
该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.
这应该可以解释您在本地看到的内容。