Question:
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 – I don’t know if I need to manually create this first.
- I definitely want this pulled into a separate branch and not my master.
Answer:
1 2 3 4 |
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:
1 2 |
git checkout foo git pull |