How to merge two or multiple git repositories into one

Vaibhav Mule
Sep 22, 2018 · 3 min read
P.S. Not endorsing Chromebooks.

You never know if you need to combine two projects into one. If you ever want to, it should be relatively simple and straightforward to do it.

Use Cases:

  • If there are two similar libraries and both of the maintainers come together to combine it.
  • And sometimes, you don’t have a choice but to have a single repository for the project.

I have used Repo A and Repo B and Repo C for demonstrating the purpose.

  • Repo A
  • Repo B
  • Repo C: This is the Repo C, where I want to merge Repo A and Repo B.

Steps to merge git repositories

I assume you are in the directory, where you want to combine the repositories, for me, it is Repo C.

This command will add a remote URL of repo-a.

Now the merging starts, it is as simple as merging any branch. This command will merge all the files and folders from .

Oops, in the real-world scenarios, it is not as simple as you think, you have to add to get it to work.

By this time, you have successfully merged the branch of to , for the reward, you are ready to grab a coffee.

Wait, you might have got merge conflicts, resolve that, and get your coffee.

Repeat the same steps for Repo B,

By this time, I was smarter, and I knew that I’m going to get an error: , so added allow-unrelated-histories beforehand.

I’m aware that I’m going to get some merge conflicts, so, I resolved it.

You should in your terminal, you will be able to see commit history as expected.

Screenshot of commits of Repo C

Exercise for learning to merge two git repositories into one:

The file content merged from repo-a and repo-b.

I’m from Repo A and B in the file looks good. I thought of adding repo named mars, and README file would have contained .

But this is the exercise which you can do.

  • Fork repo-c.
  • Create a new repo named or it can be your city or country name.
  • Merge repo to forked repo-c.
  • Create the pull request to repo c.

You see, the merging of one or multiple repositories into single repositories is simple. In the process of merging repositories, the only thing that’s going to take time is merging conflicts.

Follow me on twitter if you liked these kind of articles.


Ideas and opinions from the technical folks in hills -

Vaibhav Mule

Written by

College Dropout, Full-Stack Developer, and Aspiring Entrepreneur.



Ideas and opinions from the technical folks in hills -

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade