Skip to content

Instantly share code, notes, and snippets.

@nathanielmata
Created September 9, 2020 03:29
Show Gist options
  • Save nathanielmata/409c2445473031004b2a61cf99b778a4 to your computer and use it in GitHub Desktop.
Save nathanielmata/409c2445473031004b2a61cf99b778a4 to your computer and use it in GitHub Desktop.
Some steps to merge two repos

So you want to merge two repos?

Here are some steps that worked for me on two repos with very few merge conflicts.

If you have two repos, repoA and repoB, and you want to copy everything including the history of repoB into repoA

  1. on your local machine create a directory called temp-dir and cd into it
mkdir temp-dir
cd temp-dir
  1. inside of temp-dir clone the remote of repoB. in my case my github user is nathanielmata. substitute your username and repo name in the clone command below.
git clone git@github.com:nathanielmata/repoB.git
cd repoB
  1. list all the branches from the newly cloned repo
git branch -a
  1. Checkout all the branches that you want to copy from repoB, substituting the branch name you want in the command below
git checkout <branch-name>
  1. Now fetch all the tags from repoB
git fetch --tags
  1. Check your local tags and branches to check you got what you want
git tag
git branch -a
  1. Now clear the remote link repoB so you don't accidentally push to the repo you cloned from
git remote rm origin
  1. Now link your local repoB to your remote repoA. substitute your username and repo name in the command below
git remote add origin git@github.com:nathanielmata/repoA.git
  1. Now push all your branches and tags with these commands:
git push origin --all
git push --tags
  1. you may need to do
git push origin --allow-unrelated-histories

References


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment