I downloaded a 3rd party project as non-tracked files (without .git folder) and started a new git repository with $git init in it, to track my changes.
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.
Thanks!
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_repositorygit fetch origingit rebase FETCH_HEADYou 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).