0

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

four-eyes
  • 10,740
  • 29
  • 111
  • 220

1 Answers1

1

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

Yago Azedias
  • 4,480
  • 3
  • 17
  • 31
  • Does that preserve History? – four-eyes Apr 17 '18 at 16:56
  • I think not, it will appear in your `git log` as a Merge. I'm not totally sure, but I think that if you want to preserve the commits history you have to do a rebase – Yago Azedias Apr 17 '18 at 16:59
  • @DietrichEpp But how do I preserve the commits history in my `git log` ? – Yago Azedias Apr 17 '18 at 17:59
  • 1
    Yago: Merge preserves history in `git log`. If you look at `git log`, it will show the history of *both* branches. If you use `git log --graph`, it will show you more explicitly, or you can use something like gitk / gitx / etc. to get a graphical history. – Dietrich Epp Apr 17 '18 at 19:41