14

I've forked a repository on GitHub and have a quite an extensive commit/pull/push history, which I need to keep.

The owner of the main repository has created some new branches. How can I clone these branches into my forked copy, without deleting the fork and cloning from scratch?

1

1 Answer 1

12

You'll want to add the other repository as a remote for your own one.

Got to where you've got your repository on your computer and open git Bash and do:

git remote add upstream <address of the repository you cloned from>

Then whenever you need to update your fork just do:

git fetch upstream
git rebase upstream/master

That will reapply whatever changes are on your current branch on top of any changes from the other repository. Note to make things easier I usually leave the master branch on my repository untouched and only work in branches. Then whenever I need to update I just rebase master and rebase my other branches on top of that.

Don't know about getting other branches for upstream though but this answer may be of help: How do I check out a remote Git branch?

2
  • I think the parameters are the other way around? (At least this seems to have worked for me): git remote add upstream <address of the repository you cloned from>
    – Hugo
    May 16, 2016 at 19:09
  • Yeah, it looks like you're right. I'll fix that in my reply.
    – Sollace
    May 17, 2016 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.