Merging two Git repositories preserving existing Git history

First Git clone your current Git repository.

git clone [URL] [FOLDER]

[URL] = [email protected]:heshanlk/kickstart_base.git
[FOLDER] = kickstart_base

Now cd in to your new repository.


Now add the new remote repository.

git remote add [NEWREPO] [NEWURL]

[NEWURL] = [email protected]:heshanlk/kickstart_base_new.git
[NEWREPO] = origin_new

Pull in the upstream's code 

git pull --no-rebase --squash -Xtheirs [NEWREPO] master --allow-unrelated-histories

You should see:

Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested

Run git commit to prepare the merge for pushing to the repository

git commit -m "Adding new files"
git pull [NEWREPO] master --no-rebase --allow-unrelated-histories

Push your newly merged codebase up to your repository:

git push [NEWREPO] master