为什么不能“Git pull”从远程回购中拉出所有分支

时间:2022-08-27 23:28:06

I have a question about "git pull". Suppose I have a two remote branches "master" and "new_branch", when I use "git pull" and then use "git branch", only the "master" is shown. Why I can't see the "new branch"? I have to use "checkout new_branch" to get it shown on the local branch list. How does "checkout" work? Does it change to both local branch and remote branch?

我有一个关于“git pull”的问题。假设我有两个远程分支“master”和“new_branch”,当我使用“git pull”然后使用“git branch”时,只显示“master”。为什么我看不到“新分支”?我必须使用“checkout new_branch”将其显示在本地分支列表中。 “结账”如何运作?它是否会更改为本地分支和远程分支?

2 个解决方案

#1


Try

$ git fetch --all

it'll fetch all available branches from remote. You'll get a list like

它将从远程获取所有可用的分支。你会得到一个像这样的清单

From
* [new branch] a_new_branch -> origin/a_new_branch
* [new branch] b_new_branch -> origin/a_new_branch
3ea1234..1dz3 a_exist_branch_at_local -> origin/a_exist_branch_at_local
3ea1234..1dz4 b_exist_branch_at_local -> origin/b_exist_branch_at_local

来自* [new branch] a_new_branch - > origin / a_new_branch * [new branch] b_new_branch - > origin / a_new_branch 3ea1234..1dz3 a_exist_branch_at_local - > origin / a_exist_branch_at_local 3ea1234..1dz4 b_exist_branch_at_local - > origin / b_exist_branch_at_local

Then just checkout the new one you want:

然后检查你想要的新的:

$ git checkout a_new_branch

for old ones (exist at local), you can

对于旧的(存在于当地),你可以

$ git checkout a_exist_branch_at_local
$ git merge origin/a_exist_branch_at_local

#2


Git won't arbitrarily create local branches for you without you telling it to. However, it does keep track of the remote branches that it knows about.

没有你告诉它,Git不会随意为你创建本地分支。但是,它确实跟踪它所知道的远程分支。

$ git branch -a

will show you all the available branches on all of your remotes

将显示所有遥控器上的所有可用分支

#1


Try

$ git fetch --all

it'll fetch all available branches from remote. You'll get a list like

它将从远程获取所有可用的分支。你会得到一个像这样的清单

From
* [new branch] a_new_branch -> origin/a_new_branch
* [new branch] b_new_branch -> origin/a_new_branch
3ea1234..1dz3 a_exist_branch_at_local -> origin/a_exist_branch_at_local
3ea1234..1dz4 b_exist_branch_at_local -> origin/b_exist_branch_at_local

来自* [new branch] a_new_branch - > origin / a_new_branch * [new branch] b_new_branch - > origin / a_new_branch 3ea1234..1dz3 a_exist_branch_at_local - > origin / a_exist_branch_at_local 3ea1234..1dz4 b_exist_branch_at_local - > origin / b_exist_branch_at_local

Then just checkout the new one you want:

然后检查你想要的新的:

$ git checkout a_new_branch

for old ones (exist at local), you can

对于旧的(存在于当地),你可以

$ git checkout a_exist_branch_at_local
$ git merge origin/a_exist_branch_at_local

#2


Git won't arbitrarily create local branches for you without you telling it to. However, it does keep track of the remote branches that it knows about.

没有你告诉它,Git不会随意为你创建本地分支。但是,它确实跟踪它所知道的远程分支。

$ git branch -a

will show you all the available branches on all of your remotes

将显示所有遥控器上的所有可用分支