Combining two independent git repositories

This article presents how to combine two independent and unrelated git repositories.

First, clone the first repository locally and cd into it.

git clone URL_TO_REMOTE_1

Create a branch off the first remote

git checkout -b master-2

In order to merge a completely independent repository into the current one, delete the content of the folder apart from the .git folder. Once done, commit the changes:

git commit -m 'prepared for combining repositories'

Add the remote of the second repository

git remote add remote-2 URL_TO_REPOSITORY_2

Its content can be pulled into the current branch:

git pull remote-2 master --allow-unrelated-histories

The content of remote-2 will now be part of the git tree of the original remote, under a branch called master-2.

Master-2 can be merged into master one to finish the combination of the repositories.