1

I followed this https://help.github.com/articles/fork-a-repo post to clone a repository locally. After doing that another developer created a branch to the main repository and added some features to that branch. My question is

  1. How do I get that branch into my fork.
  2. Can I get that missing branch again to my local using git pull upstream/missing_branch command?

Thank you

Harish
  • 1,469
  • 16
  • 43

1 Answers1

1

You need to add a remote repo 'upstream' in the local repo (which has for origin your fork)

upstream and fork

(git remote man page)

git remote add upstream url://upstream/repo

The OP opensourcelover mentions seeing this:

git remote -v, 

origin git@github.com:username/project.git (fetch) 
origin git@github.com:username/project.git (push) 
upstream git@github.com:username/project.git (fetch) 
upstream git@github.com:username/project.git (push) 

If your origin is the same as your upstream remote repo, you can replace that url by the https one for that upstream:

git remote set-url upstream https://github.com/originalDevName/originalRepoName

That way, you can git fetch upstream and get the new branch.

If you need to work on that new branch, you can now declare it:

git branch -u upstream/foo foo

See "How do you make an existing Git branch track a remote branch?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I did that. when I run git remote -v, I get this origin git@github.com:username/project.git (fetch) origin git@github.com:username/project.git (push) upstream git@github.com:username/project.git (fetch) upstream git@github.com:username/project.git (push) so when I try running git fetch upstream it doesn't pull anything. – Harish Apr 11 '13 at 19:40
  • so when I run git branch -u upstream/foo foo on the my project level directory, is that going to overrite my existing files ? – Harish Apr 11 '13 at 20:27
  • @opensourcelover no: only declare a new branch. You can then checkout that new branch (and your working tree will be updated), or merge it to your current branch. – VonC Apr 11 '13 at 20:53