four-eyes
four-eyes

Reputation: 12459

Merge two different repositories into one and preserving the history

I cloned and forked a repository from here source: https://github.com/react-community/react-native-maps resulting in two different repositories.

Clone Repo: https://github.com/Stophface/react-native-maps-0.20.1 (repo 1)

Fork Repo: https://github.com/Stophface/react-native-maps (repo 2)

Now I want to merge the Clone Repo (repo 1) into the Fork Repo (repo 2), preserving history if possible. Is that even possible?

I followed the instructions here. When I try to merge the Clone repo(repo 1) into the Forked Repo(repo 2) I get the error

fatal: refusing to merge unrelated histories

Upvotes: 0

Views: 162

Answers (1)

Yago Azedias
Yago Azedias

Reputation: 4878

Add "repo1" as a remote and merge it into "repo2"

You can just added the repo1 as a new remote and them merge it into your local repository:

  1. Clone the fork https://github.com/Stophface/react-native-maps

    git clone https://github.com/Stophface/react-native-maps && cd react-native-maps

  2. Add a new remote to your local repository

    git remote add repo1-origin https://github.com/Stophface/react-native-maps-0.20.1

  3. Merge the content from remote repo1-origin into your local fork (repo2)

    git pull repo1-origin [branch-name]

OBS: Both of a rebase or a simple merge will preserve your git history, but if you want to preserve the commits chronology in your git log, I recommend you to do rebase:

  • git pull --rebase repo1-origin [branch-name]

That way you will merge the two contents

Upvotes: 1

Related Questions