AltCampus
Published in

AltCampus

How to merge two or multiple git repositories into one

P.S. Not endorsing Chromebooks.

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.
  • 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

git remote add -f repo-a git@github.com:vaibhavmule/repo-a.git
git merge repo-a/master
fatal: refusing to merge unrelated histories
git merge repo-a/master --allow-unrelated-histories

Repeat the same steps for Repo B,

git remote add -f repo-b git@github.com:vaibhavmule/repo-b.git
git merge repo-b/master --allow-unrelated-histories
Screenshot of commits of Repo C

Exercise for learning to merge two git repositories into one:

The README.md file content merged from repo-a and repo-b.
  • Fork repo-c.
  • Create a new repo named mars or it can be your city or country name.
  • Merge mars repo to forked repo-c.
  • Create the pull request to repo c.

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

--

--

Ideas and opinions from the technical folks in hills - https://altcampus.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vaibhav Mule

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