Merging two Github repositories + history.

Gulnoza Muminova
2 min readApr 22, 2020

--

If you want to merge two Github repos and do not lose a commit history, let’s do it right now :)

After these steps, your repo second will be in repo first directory with all history of repo first and repo second.

Important!!! First, try it with test repositories, so if you will do mistakes that's fine. When you got it right then do it with original repos.

Let’s clone repo ‘first’ into your machine:

git clone https://github.com/Gulnoz/firstGo to the cloned repo in your terminal:cd firstNext check remote repos within it:git remote -vChecking existed branches within this:git branch -a -vvNow we need to add second repo as remote to the first repo:git remote add second https://github.com/Gulnoz/secondFetching everithing from second repo:git fetch secondWe will need to create new branch for moving everithing around, lets create branch with name second:git checkout -b second second/masterDo not make a mess with all files during merching two repos, lets create new folder and move everything from second repo to that folder:mkdir secondgit mv !(second) secondCommiting moving files into subdirectory:git commit -m "Moved second into subdirectory"Changing branch from second to master:git checkout masterFinaly merging second with first repos including history:git merge second --allow-unrelated-historiesCommit our merging repos and pushing into remote first:git commit -m "merging"git pushNow let's clean up :)Removing second repo remote from first repo:git remote rm secondDeleting branch second, we do not need it any more:git branch -d secondLet's check our branches:git branch -a -v

That’s it! I hope you found this helpful. Good luck!

Addition resources:

--

--