简体   繁体   English

如何将远程分支添加到我的本地仓库?

[英]How to add a remote branch to my local repo?

So I haven't found any answers that explains this in a way that I understand.所以我还没有找到任何答案以我理解的方式解释这一点。 So how do I add a remote branch to my local repo using git?那么如何使用 git 将远程分支添加到本地存储库?

A simple git fetch should be enough.一个简单的git fetch就足够了。

Type类型

cd /path/to/local/repo/on/first/computer
git fetch
git branch -avv

You should see the new branches listed as origin/xxx (namespace ' origin ')您应该会看到列为origin/xxx的新分支(命名空间 ' origin ')

A git switch xxx will create a local branch based on that remote tracking branch origin/xxx . git switch xxx将基于该远程跟踪分支origin/xxx创建一个本地分支。

That will also update your Git repository working tree (ie, your files), which will make them visible in your IDE/editor.这也将更新您的 Git 存储库工作树(即您的文件),这将使它们在您的 IDE/编辑器中可见。

I think others did not understand your question.我认为其他人不理解您的问题。

You are trying to bring down to your local machine a remote branch that you currently do not have.您正在尝试将您当前没有的远程分支带到本地计算机 This could happen if, for instance, your colleague created a new branch.例如,如果您的同事创建了一个新分支,则可能会发生这种情况。

Now that git switch has been added, this is simple:现在已经添加了git switch ,这很简单:

git switch <name of remote branch>

Since you do not have the branch locally, this will automatically make switch look on the remote repo.由于您在本地没有分支,这将自动使switch在远程 repo 上查找。 It will then also automatically set up remote branch tracking.然后它还将自动设置远程分支跟踪。

Lastly, this has already been discussed a bunch here on SO.最后,这已经在 SO 上讨论了很多。 You can look here for more answers, but some are outdated.你可以在这里寻找更多答案,但有些已经过时了。

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

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