简体   繁体   English

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

[英]Git is not showing all branches on local

I forked a repo from Github. 我从Github分了一个回购。 On doing git remote -v it displays: 在做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.git has about 10 branches, but the repo shows only 2 of them. moodle.git有大约10个分支,但回购只显示其中的2个。 On doing git branch -a (show all branches) I get: 在做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? 如何在不丢失任何数据或任何违规行为的情况下解决问题?

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. 克隆一个repo不会复制本地repo上的所有远程分支:对于一个包含大量分支的大型远程仓库,这会使你的本地命名空间被大量的分支污染。

I have a one-liner command in 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 --track allows for setting up the configuration to mark the start-point branch as " upstream " from the new branch. 添加--track允许设置配置以将起点分支标记为来自新分支的“ 上游 ”。
This configuration will tell git to show the relationship between the two branches in git status and git branch -v . 这个配置会告诉git在git statusgit branch -v显示两个分支之间的关系。
Furthermore, it directs git pull without arguments to pull from the upstream when the new branch is checked out. 此外,它在没有参数的情况下引导git pull在检出新分支时从上游拉出。


kostix mentions that --track is implied when forking a branch off a remote branch (unless branch.autosetupmerge is set to false ) kostix提到--track是隐含的分叉的分支时关闭远程分支(除非branch.autosetupmerge被设置为false

This could be enough 这可能就足够了

git checkout aBranch

The exact explanation from git checkout man page is: 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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM