克隆Git仓库后,只有主分支可见 [英] Only master branch is visible after cloning a Git repo

查看:363
本文介绍了克隆Git仓库后,只有主分支可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,并创建了一个包含 master 分支的存储库。正在处理它的人添加了一个名为 new-branch 的分支 - 它们的代码更改位于此分支中。

I am working on a project and I created a repository with a master branch. Someone who is working on it added a branch named new-branch -- their code changes are in this branch.

然而,当我克隆版本库时:

However, when I clone the repository:

$ git clone git@github.com:me/my-repo.git

我可以成功克隆它,但它只显示 master 分支。我不知道如何查看/获取新分支

I can clone it successfully, but it only shows the master branch. I do not know how I can view/get the new-branch.

我如何将此分支拉到我的存储库?

How would I pull this branch to my repository?

推荐答案

当您克隆存储库时,所有远程分支都会创建为存储库中的远程跟踪分支。这些默认情况下不显示,但你可以看到这些:

When you clone a repository, all remote branches are created as "remote tracking branches" in your repository. These aren't shown by default, but you can see these with:

git branch -a

如果您执行 git checkout new-branch ,git会找到远程跟踪同名分支,自动从同一提交中创建一个新的本地分支,并切换到新的本地分支。

If you do a git checkout new-branch, git will find the remote tracking branch of the same name, automatically create a new local branch from the same commit, and switch to the new local branch.

对于未来的工作, git fetch 命令将使用远程的最新提交来更新所有远程跟踪分支。

For future work, the git fetch command will update all the remote tracking branches with their latest commit from the remote.

这篇关于克隆Git仓库后,只有主分支可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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