git Git没有显示本地的所有分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15721949/
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-10 15:52:56  来源:igfitidea点击:

Git is not showing all branches on local

gitgithubmoodlegit-remote

提问by xan

I forked a repo from Github. On doing git remote -vit displays:

我从 Github 分叉了一个 repo。在这样做git remote -v时显示:

origin  https://github.com/myusername/moodle.git (fetch)
origin  https://github.com/myusername/moodle.git (push)
upstream    https://github.com/moodle/moodle.git (fetch)
upstream    https://github.com/moodle/moodle.git (push)

The moodle.githas about 10 branches, but the repo shows only 2 of them. On doing git branch -a(show all branches) I get:

moodle.git有大约10家分公司,但回购只显示其中的2。在做git branch -a(显示所有分支)时,我得到:

  MOODLE_24_STABLE// just these two on local..how?
* master//
  origin/MOODLE_13_STABLE
  origin/MOODLE_14_STABLE
  origin/MOODLE_15_STABLE
  origin/MOODLE_16_STABLE
  origin/MOODLE_17_STABLE
  origin/MOODLE_18_STABLE
  origin/MOODLE_19_STABLE
  origin/MOODLE_20_STABLE
  origin/MOODLE_21_STABLE
  origin/MOODLE_22_STABLE
  origin/MOODLE_23_STABLE
  origin/MOODLE_24_STABLE
  origin/master
  upstream/MOODLE_13_STABLE
  upstream/MOODLE_14_STABLE
  upstream/MOODLE_15_STABLE
  upstream/MOODLE_16_STABLE
  upstream/MOODLE_17_STABLE
  upstream/MOODLE_18_STABLE
  upstream/MOODLE_19_STABLE
  upstream/MOODLE_20_STABLE
  upstream/MOODLE_21_STABLE
  upstream/MOODLE_22_STABLE
  upstream/MOODLE_23_STABLE
  upstream/MOODLE_24_STABLE
  upstream/master

How do I resolve my problem without any loss of data or any irregularities?

如何在不丢失任何数据或任何违规行为的情况下解决我的问题?

回答by VonC

Cloning a repo won't duplicate all the remote branches on the local repo: for a large remote repo with a lot of branches, that would pollute your local namespace with tons of branches.

克隆存储库不会复制本地存储库上的所有远程分支:对于具有大量分支的大型远程存储库,这会用大量分支污染您的本地命名空间。

I have a one-liner commandin order to create local branches tracking all the remote branches of a remote repo, but this is usually not needed.
You only create a local branch tracking a remote one when needed.

我有一个单行命令来创建本地分支,跟踪远程仓库的所有远程分支,但这通常是不需要的。
您只在需要时创建一个跟踪远程分支的本地分支。

git checkout -b aBranch --track origin/aBranch

# or, shorter:
$ git checkout --track origin/aBranch 
Branch aBranch set up to track remote branch refs/remotes/origin/aBranch.
Switched to a new branch "aBranch"  

# even shorter at the end of this answer.

Adding a --trackallows for setting up the configuration to mark the start-point branch as "upstream" from the new branch.
This configuration will tell git to show the relationship between the two branches in git statusand git branch -v.
Furthermore, it directs git pull without arguments to pull from the upstream when the new branch is checked out.

添加一个--track允许设置配置以将起点分支标记为新分支的“上游”。
这个配置会告诉 git 在git status和 中显示两个分支之间的关系git branch -v
此外,当签出新分支时,它会指示 git pull 不带参数从上游拉取。



kostixmentions that --trackis implied when forking a branch off a remote branch (unless branch.autosetupmergeis set to false)

kostix提到--track在从远程分支分支分支时隐含的(除非branch.autosetupmerge设置为false

This could be enough

这可能就足够了

git checkout aBranch

The exact explanation from git checkoutman pageis:

git checkout手册页的确切解释是:

If <branch>is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to:

如果<branch>未找到,但在一个<remote>具有匹配名称的远程(称为)中确实存在跟踪分支,则视为等效于:

$ git checkout -b <branch> --track <remote>/<branch

回答by Grace Aloysius

Some times , if you havn't pulled the latest code, you wont be allowed to checkout the newly created branch.Because your changes are not in synch.

有时,如果你没有拉取最新的代码,你将不被允许检出新创建的分支。因为你的更改不同步。

So first -pull the latest -checkout from newly created branch

所以首先从新创建的分支中拉取最新的 -checkout