How to change a fresh git repository into a branch from another repo?
I later found out that this project already has a public git repository, which has the same state as the bare files I downloaded (is identical to my initial commit).
What I should have done:
Cloned the remote repo and made a new local branch and then pushed it to remote.
What I actually did:
Just took the files and started a clean local git repo (master) in it and made several commits.
What I want to do:
Turn my local initial commit into a branch of the remote repo (change its parent) and keep the changes I’ve already done.
I guess this should be possible, but I don’t know enough Git.
2 Solutions collect form web for “How to change a fresh git repository into a branch from another repo?”
Well, you could try the following (you may want to use a different name than
origin, up to you):
git remote add origin url_of_project_repository
git fetch origin
git rebase FETCH_HEAD
You have significant chances git will actually figure ot your base and the new remote’s are actually the same set of files, and will resolve the fake merge conflict by skipping anything but your changes.
If that doesn’t work peroperly, you could also juts clone the “real” repository somewhere else, then re-apply your changes on top of it (and there would be countless ways of doing this, from a very manual DIY way to some more automated means).
You can add your repo as a remote to the original one, fetch the commits, and try to rebase.