Search code examples
gitbfg-repo-cleaner

Migrating unpushed local commits to new repository


We have a problem that our repository size exceeded the allowed limit and we are now blocked to push any local commit.

So we used bfg to remove big files and re-write the whole history of the repository then pushed it to a new one, in meanwhile multiple commits were produced by other developers.

I want to know a simple way to move the commits that we couldn't push into the new repository? as I don't want to apply each change manually.


Solution

  • I think I found a nice solution based on this question

    I did the following:

    1. Add oldRepo remote pointing to old repository folder
    git remote add oldRepo <oldRepoPath>/.git
    git fetch oldRepo
    
    1. Repeat the following for each branch you want to migrate its commits
    git checkout <yourBranch>
    git cherry-pick <OldestUnpushedCommitSHA>..<LatestsUnpushedCommitSHA>
    git push
    
    1. At the end remove oldRepo remote
    git remote remove oldRepo