简体   繁体   English

从远程存储库更新本地github存储库中的分支

[英]Update branch in my local github repository from remote repository

I forked a github repository to my local github account and was working on the master branch for sometime. 我将github存储库分支到了我的本地github帐户,并且在master分支上工作了一段时间。 After this the original repository had a new branch created which is not there in my local forked repository. 此后,原始存储库创建了一个新分支,该分支不在我的本地分叉存储库中。 I normally update my local repository using "git pull upstream master". 我通常使用“ git pull上游主服务器”更新本地存储库。 Now I want to work on the new branch created in the original repository and wondering how do I update my local repository to add the new branch. 现在,我要处理在原始存储库中创建的新分支,并想知道如何更新本地存储库以添加新分支。

First git fetch upstream to make sure you have a local copy of the most recent versions of the remote refs (branches). 首先git fetch upstream ,以确保您具有远程引用(分支)的最新版本的本地副本。 This is implicitly done each time you git pull upstream anyway, but it can't hurt to check again before creating your local branch) 每当您git pull upstream时,都会隐式地完成此操作,但是在创建本地分支之前再次检查不会有任何伤害)

Then you can create your local instance of the branch with git checkout <branchName> . 然后,您可以使用git checkout <branchName>创建分支的本地实例。

If you're unsure about the branch name, check it in the output of git branch -r which lists the list of branches you updated with the earlier fetch . 如果不确定分支名称,请在git branch -r的输出中检查它,该输出列出了使用较早的fetch更新的分支的列表。

However, don't checkout the remote branch but the local counterpart. 但是,不要签出远程分支,而要签出本地分支。

For example : NOT git checkout remotes/origin/my_branch which would end up in a detached HEAD state pointing to the commit this remote ref happened to point to. 例如:NOT git checkout remotes/origin/my_branch最终将以分离的HEAD状态结束,指向此远程引用恰好指向的提交。 What you want to checkout is git checkout my_branch if your config sets upstream automatically, adding the option --set-upstream-to=remotes/origin/my_branch if it's not the case. 如果您的配置自动将上游设置为上游,您要检出的是git checkout my_branch如果git checkout my_branch这样,则添加选项--set-upstream-to=remotes/origin/my_branch

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

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