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
- on your local machine create a directory called temp-dir and cd into it
mkdir temp-dir
cd temp-dir
- 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
- list all the branches from the newly cloned repo
git branch -a
- 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>
- Now fetch all the tags from repoB
git fetch --tags
- Check your local tags and branches to check you got what you want
git tag
git branch -a
- Now clear the remote link repoB so you don't accidentally push to the repo you cloned from
git remote rm origin
- 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
- Now push all your branches and tags with these commands:
git push origin --all
git push --tags
- you may need to do
git push origin --allow-unrelated-histories