如何从别人的回购中拉远程分支 [英] How to pull remote branch from somebody else's repo
问题描述
我有一个项目托管在GitHub上,这是有人分享的。在他们的分支上,他们创建了一个新的分支foo并做了一些修改。我如何将他们的foo拉入一个新的分支,在我的回购库中也被命名为foo?我知道他们可以向我提交一个pull请求,
- 因为我喜欢自己发起这个过程。他们分叉我的项目,我们的回购协议共享相同的'历史记录'尽管GitHub显示他们的项目是从我的分支中创建的,但我的本地存储库没有任何对该项目的引用。我是否需要将它们添加为远程?
- 我没有一个名为foo的分支 - 不知道是否需要手动创建第一个或哪些内容。
- 我希望把它拉到一个单独的分支中,而不是我的主人。
。
git remote添加同事git:// path / to / coworkers / repo .git
git fetch同事
git checkout --track同事/ foo
这将设置一个本地分支 foo
,跟踪远程分支 coworker / foo
。所以当你的同事做出一些改变时,你可以很容易地将它们拉出来:
git checkout foo
git pull
对评论的回应:
酷:)如果我想让我自己的
更改为该分支,我应该
创建第二个本地分支 bar
fromfoo,直接在我的foo上工作而不是
?
您即使我推荐它,也不需要创建新的分支。你可以直接向 foo
提交,让你的同事拉你的分支。但是那个分支已经存在了,你的分支 foo
需要设置为它的上游分支:
git branch --set-upstream foo colin / foo
假设 colin
是以类似方式定义的您的存储库(您的同事存储库的远程存储库):
git remote add colin git://path/to/colins/repo.git
I've got a project hosted on GitHub which somebody has forked. On their fork, they've created a new branch "foo" and made some changes. How do I pull their "foo" into a new branch also named "foo" in my repo?
I understand they could submit a pull request to me, but I'd like to initiate this process myself.
Assume the following:
- Because they forked my project, both our repos share the same 'history'
- Although GitHub shows their project was forked from mine, my local repository doesn't have any references to this person's project. Do I need to add theirs as a remote?
- I don't have a branch called "foo" yet - dunno if I need to manually create this first or what.
- I definitely want this pulled into a separate branch and not my master.
I hope that makes some sense.
git remote add coworker git://path/to/coworkers/repo.git
git fetch coworker
git checkout --track coworker/foo
This will setup a local branch foo
, tracking the remote branch coworker/foo
. So when your co-worker has made some changes, you can easily pull them:
git checkout foo
git pull
Response to comments:
Cool :) And if I'd like to make my own changes to that branch, should I create a second local branch "bar" from "foo" and work there instead of directly on my "foo"?
You don't need to create a new branch, even though I recommend it. You might as well commit directly to foo
and have your co-worker pull your branch. But that branch already exists and your branch foo
need to be setup as an upstream branch to it:
git branch --set-upstream foo colin/foo
assuming colin
is your repository (a remote to your co-workers repository) defined in similar way:
git remote add colin git://path/to/colins/repo.git
这篇关于如何从别人的回购中拉远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!