1

How do I achieve the following? I have a new repo New_Repo which is the current repo we all are working on. I would like to create WhatINeed, but have repeatedly failed to do so.

I understand that the commit ID will change and we are fine with this.

Old_Repo ........................... (Master, which is also v1)
            |......... (ModA) 

New_Repo.(Empty Master)
        |............. (v2)

WHatINeed.(Empty Master)
         |........................... (v1)
         |       |......... (ModA)
         |............. (v2)

I have been able to get to add the Old_repo/master onto the WhatINeed master. But its not a branch like I want it.

I am already refering to Insert a commit before the root commit in Git? But this gives me a flat structure without the ModA branch. Is there something wrong?

Thank you in advance.

  • First, define what you mean by *branch*. See http://stackoverflow.com/questions/25068543/what-exactly-do-we-mean-by-branch – torek Apr 06 '18 at 23:56
  • Possible duplicate of [Import unrelated repository to another repository branch](https://stackoverflow.com/questions/27784385/import-unrelated-repository-to-another-repository-branch) – jaco0646 Apr 07 '18 at 22:25

1 Answers1

0

If I understand correctly, you want to create a new branch (say, oldRepoBranch) into WhatINeed repo that will have the same commit history of Old_Repo's master branch.

Add a new remote (say, oldRepo) with the url of Old_Repo into WhatINeed repo.

// WhatINeed repo
$ git remote add oldRepo <Old_Repo url> 
$ git fetch oldRepo

Create a new branch oldRepoBranch with the history of ldRepo/master.

$ git checkout -b oldRepoBranch oldRepo/master
$ git log 
// oldRepoBranch commit history = Old_Repo/master commit history
jsageryd
  • 4,234
  • 21
  • 34
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • Thanks @sajib-khan. Now I have two remotes. How do I get rid of the and just use the new one? –  Apr 16 '18 at 23:52
  • remote `origin` still exists that is the new repo actually. So, you can use remote `origin` for pull/push/etc. you can also delete the oldRepo remote but not mandatory (`$ git remote rm oldRepo`) – Sajib Khan Apr 17 '18 at 01:46