克隆 Git 存储库后只有主分支可见

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

Only master branch is visible after cloning a Git repo

git

提问by David542

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

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

However, when I clone the repository:

但是,当我克隆存储库时:

$ git clone [email protected]:me/my-repo.git

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

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

How would I pull this branch to my repository?

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

回答by Greg Hewgill

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

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 checkout new-branch,git 会找到同名的远程跟踪分支,自动从同一个提交创建一个新的本地分支,并切换到新的本地分支。

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

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