How to change a fresh git repository into a branch from another repo?

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).

  • how to request pull request from a particular remote in git?
  • Cannot checkout, file is unmerged
  • how to read index diff --git output
  • Should I add the Visual Studio 2015 .vs folder to source control?
  • Manage different codebases using single git repository instead of submodules
  • How can I check for whitespace/tab errors in my git 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.


  • How to get rid of remote origin/HEAD pointing to origin/master?
  • git hook post-merge - error: cannot run
  • Working with a forked git repository, except I cloned the public repo URL, not the private URL
  • Is it possible to add patch sets to a Gerrit review without ammending/squashing commits
  • Keep getting prompted for SSH passphrase in Git
  • Change case of a file on Windows?
  • 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):

    1. git remote add origin url_of_project_repository
    2. git fetch origin
    3. 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.

    Git Baby is a git and github fan, let's start git clone.