0

I am new to Github and i have a question that i have been trying to find an answer.
Say i have three repositories, Origin, Repo1 (my repo - forked from Origin), Repo2 (my colleague's repo forked from Origin).
We work on our own repos, and then make pull requests to origin.

How can I clone my colleague's repo2/branch1 into my local repo? If i use git pull, it merges my local branch into repo2/branch1. What i want is to create a new branch in my local repo which contains exactly and only what is in repo2/branch1. Is there a command to do that ?

What i have to do now everytime i want to do something similar is "CLONE" the whole repo2 which is time consuming and problematic.

Thanks very much.

UPDATE ANSWER

git fetch repo2
git checkout -b repo2_branch1 repo2/branch1 

will remote track branch1 of repo2 on my local machine as a branch called repo2_branch1.

user2070333
  • 335
  • 2
  • 11
  • 2
    Possible duplicate of [How to pull remote branch from somebody else's repo](http://stackoverflow.com/questions/5884784/how-to-pull-remote-branch-from-somebody-elses-repo) – Shiva Aug 17 '16 at 20:35

1 Answers1

0

Create a new branch in your repo (Repo1).

git checkout -b trackRepo2

This will start will your code base, and you'll have to merge the changes made by your friend to it. Proceed as follows.

Add your friends repo as a remote for this new branch

git remote add git_Repo2 <address of Repo2>

Now, simply do a pull (or a fetch and merge) from your friend's repo, using the following command.

git pull git_Repo2 master

Assuming it's master branch of Repo2 that you are interested in. You can also set the branch master at Repo2 as your default upstream branch for your local branch trackRepo2, then you'll just have to do git pull , without mentioning git_Repo2 master every time.

Sahil Singh
  • 3,352
  • 39
  • 62