Akira Okumura
Akira Okumura

Reputation: 1965

How do I import a specific branch of a Git repository to another repository?

I have an organization on GitHub, in which two repositories exist. One is a C++ library, and the other is an HTML repository.

Let's assume that they are located in the following repositories. https://github.com/MyOrganization/mylibrary.git https://github.com/MyOrganization/myorganization.github.io.git

I would like to import only branch gh-pages of milibrary.git to myorganization.github.io.git with its history being kept, but I do not know how to do it. Would anyone kindly tell me appropriate commands?

My motivation is to migrate the home page of http://myorganization.github.io/MyLibrary/ to http://myorganization.github.io/

Upvotes: 4

Views: 15835

Answers (2)

Harish Ved
Harish Ved

Reputation: 570

Try -

git clone https://github.com/MyOrganization/myorganization.github.io.git
cd myorganization.github.io.git
git remote add other https://github.com/MyOrganization/mylibrary.git
git fetch other
git checkout -b gh-pages --track other/gh_pages
git remote remove other

Upvotes: 4

Ionică Bizău
Ionică Bizău

Reputation: 113385

Follow the next steps:

git clone https://github.com/MyOrganization/myorganization.github.io website
cd website
git pull https://github.com/MyOrganization/mylibrary.git gh-pages
git push

This will download your gh-pages branch and merge it into your default branch from website repository.

You may have some conflicts to solve.

Upvotes: 4

Related Questions