中克隆所有远程分支

中克隆所有远程分支

本文介绍了如何在 Git 中克隆所有远程分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 master 和一个 development 分支,都推送到 GitHub.我已经cloned、pulled 和fetched,但我仍然无法获得除master 以外的任何东西代码>分支回来.

I have a master and a development branch, both pushed to GitHub. I've cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back.

我确定我遗漏了一些明显的东西,但我已经阅读了手册,但我一点也不高兴.

I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all.

推荐答案

首先,克隆一个远程 Git 存储库和 cd 到其中:

First, clone a remote Git repository and cd into it:

$ git clone git://example.com/myproject
$ cd myproject

接下来,查看仓库中的本地分支:

Next, look at the local branches in your repository:

$ git branch
* master

但是还有其他分支隐藏在您的存储库中!您可以使用 -a 标志查看这些:

But there are other branches hiding in your repository! You can see these using the -a flag:

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

如果你只是想快速浏览一下上游分支,可以直接查看:

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

但是如果您想在该分支上工作,您需要创建一个本地跟踪分支,该分支通过以下方式自动完成:

But if you want to work on that branch, you'll need to create a local tracking branch which is done automatically by:

$ git checkout experimental

你会看到

Branch experimental set up to track remote branch experimental from origin.
Switched to a new branch 'experimental'

这里是新分支"只是意味着分支取自索引并在本地为您创建.正如上一行告诉您的那样,分支正在设置以跟踪远程分支,这通常意味着 origin/branch_name 分支.

Here, "new branch" simply means that the branch is taken from the index and created locally for you. As the previous line tells you, the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.

现在,如果您查看本地分支机构,您会看到以下内容:

Now, if you look at your local branches, this is what you'll see:

$ git branch
* experimental
  master

您实际上可以使用 git remote 跟踪多个远程存储库.

You can actually track more than one remote repository using git remote.

$ git remote add win32 git://example.com/users/joe/myproject-win32-port
$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental
  remotes/win32/master
  remotes/win32/new-widgets

此时,事情变得非常疯狂,所以运行 gitk 看看发生了什么:

At this point, things are getting pretty crazy, so run gitk to see what's going on:

$ gitk --all &

这篇关于如何在 Git 中克隆所有远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:33