1

So I forked a public git repo and then created a new local git repo where I copied the files into, did a hundred or so commits and now I would like to change my local git repo to be a fork of the original repo and re-sign all of my commits.

Is this possible?

I imagine I should be able to go back to the first commit in my locale repo and then somehow pull the original public git repo into a new commit and then rebase all my local commits on top of that.

But I don't know how to do it.

dotnetCarpenter
  • 10,019
  • 6
  • 32
  • 54

1 Answers1

0

created a new local git repo where I copied the files into

The right move would have been to clone your fork.

I would like to change my local git repo to be a fork of the original repo and re-sign all of my commits

Actually, don't touch your current local repo.

Clone your GitHub fork repo locally (a second local repo), and rebase your commit from the first repo onto a dedicated branch:

cd second
git checkout -b myBranch
git remote add first ../first

(../first is the relative path to the second repo local folder of your current first repo)

git fetch first.
git rebase --onto myBranch $(git rev-list --max-parents=0 first/master) first/master

(here I assume you put commits on the master branch.)
(See "How to show first commit by 'git log'?")

That will replay all your commits after the very first one of your first repo (assuming that the first commit was the one with the copied files, before you started adding your own), up to the last commit of your first repo, onto your new dedicated branch.

Push that newBranch to your fork, and you are all set.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC but I'm sorry. It sounds great but I can't seem to wrap my head around what is the first repo - is it the repo where I copied the files from my github clone into? My github fork is `webviewer5` and the local repo where I copied files into is called `pspdfkit`. So I do `git clone webviewer5/ second` and inside `second` I create a branch and do `git remote add first ../webviewer5/`. Then what do I do with the repo I want to rebase my commits from; `pspdfkit`? I really agree that I should have forked to begin with but I wrongly assumed it was going to be a throw-away demo repo. – dotnetCarpenter Jul 22 '18 at 23:43
  • Actually I think it worked! But now I'm in a `detached` state and I'm afraid to loose the rebase if I checkout master again... – dotnetCarpenter Jul 23 '18 at 00:06
  • The last thing to do is to do a `checkout` ala `git checkout -b same_history` and the branch `same_history has now joint history with the original github repo. – dotnetCarpenter Jul 23 '18 at 00:08