如何克隆Git中的所有远程分支? [英] How to clone all remote branches in Git?

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

问题描述

我有一个 master 和一个开发分支,它们都被推送到 GitHub 。我有 clone d, pull ed, fetch 但我仍然无法获得除 master 分支之外的任何其他内容。



我确定我'我错过了一些显而易见的东西,但是我已经阅读了手册,并且我没有得到任何喜悦。 解决方案

首先,克隆一个远程 Git 存储库和

  $ git克隆git://example.com/myproject 
$ cd myproject

接下来,看看您的存储库中的本地分支机构:

  $ git branch 
* master

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

  $ git分支-a 
* master
遥控器/原点/ HEAD
遥控器/原点/主控器
遥控器/原点/ v1.0-稳定器
遥控器/原点/试验器

如果您只想快速查看上游分支,可以直接查看它:

  $ git checkout origin / experimental 

但是如果你想在那个分支上工作,你需要创建一个本地跟踪分支,它可以自动完成:

  $ git checkout experimental 

您会看到

 分支实验设置用于跟踪从原点开始的远程分支实验。 
切换到一个新的分支'实验'

最后一行引出一些人:New分支 - 嗯?
它的真正含义是该分支从索引中获取并在本地为您创建。 前面的行实际上更具信息性,因为它告诉你该分支正在设置为跟踪远程分支,通常意味着origin / branch_name分支



现在,如果你看看你的本地分支,这就是你会看到的:

  $ git branch 
* experimental
master

实际上,您可以使用 git remote

  $ git remote add win32 git:// example。 com / users / joe / myproject-win32-port 
$ git branch -a
* master
遥控器/原点/ HEAD
遥控器/原点/主控器
遥控器/原产地/ v1.0-stable
遥控器/原产地/实验型
遥控器/ win32 / master
遥控器/ win32 /新建窗口小部件

在这一点上,事情变得非常疯狂,所以运行 gitk 来看看发生了什么:

  $ gitk --all& 


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.

解决方案

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

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

and you will see

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

That last line throws some people: "New branch" - huh? What it really means is that the branch is taken from the index and created locally for you. The previous line is actually more informative as it tells you that 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

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

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

$ gitk --all &

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆