Join old and new repo, created by copying files (not cloning), preserving commit history

To simplify things I have the following structure in git old_repo for


I decided to move to a new_repo and just copied the latest version of “subpath” (from old_commit_latest) into it without any commit history.

  • Git check custom rules
  • Moving large number of large files in git repository
  • Atlassian Stash and git SSL issue
  • git - diff of current changes before committing
  • equivalence of: git log --exclude-author?
  • Is there a way to “autosign” commits in Git with a GPG key?
  • So the new_repo now has “subpath” and a bunch of new commits I made to it:

    subpath/new_commit_subpath_added # added subpath here

    Now I need to migrate all the history from old_repo to the new_repo to get the following tree in new_repo:


    How do I do that?

    I only need to do it to master branch, but I have lots of files there in the same situation. And subpath and filenames in old_repo matches the ones in new_repo.

    I guess I need to create patches for subpaths in old_repo, rollback to the first commit for each subpath in the new_repo, remove that first commit, apply patches and then rebase all the new commits over it. Not sure how to do it all. Will appreciate some help.

  • Get git like option completion in python program
  • Check out Git with Chef and Vagrant
  • Giving priority to GIT in GIT/SVN mixed project in Netbeans?
  • In Visual Studio 2015 how to reverse/undo a commit in Git?
  • How do I make git post-receive emails be sent from the commit author?
  • git-svn stops with no error message when trying to clone
  • One Solution collect form web for “Join old and new repo, created by copying files (not cloning), preserving commit history”


    You should have both new and old versions available as valid repositories. The old version should better be on your local machine, new can be on local or remote (say, github).

    It’s always a good idea to have backups of both repos and projects.

    I assume that the last commit of old version is exactly the first commit of the new. If that’s not so:

    1. Reset the newer version to it’s first commit.
    2. Delete the files in older version project folder except .git, but including .gitignore and other git settings.
    3. Copy the files from newer to older version project folder.
    4. Save all changes as a new commit on old/master.

    Joining repositories

    # go to the old repo folder
    cd path/to/old
    # add the new repo as a remote
    git add remote newrepo path/to/new/.git
    #check that it's properly added
    git remote show newrepo
    #fetch data from new
    git fetch newrepo
    #create a branch "new", tracking
    git checkout -b new newrepo/master
    #merge changes to the old master
    git checkout master
    git merge newrepo
    #an editor will open with a merge commit message. If you've done the preparations, there should be no merge conflicts.
    #this should show a complete history now
    git log --oneline

    Now you have the joint history and latest commits in the old project directory.

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