Some of these methods dint work out for me as the new repo where I wanted to shift contents had one initial commit already made with some changes when setting up new repo (files like README etc.)
Steps that worked for me:
1.In github remote of repo1 create a new branch from master(say snapshot
).
2.Mirror repo1 in local
git clone --mirror **url-of-repo1**
3.Navigate to repo1 and then set new remote to the repo2:
git remote remove origin
git remote add origin **url-of-repo2**
4.Push all tracks and tags to new remote. master will get rejected but rest all are will be fine:
git push --all
git push --tags
5.Clear out mirrored repo from local:
rm -rf repo1.git
6.Clone the repo2 now in local, then navigate inside:
git clone **url-of-repo2.git**
cd repo2
7.Checkout to snapshot
branch then:
git checkout --track origin/snapshot
8.Checkout to master and then merge with snapshot:
git merge snapshot --allow-unrelated-histories
9.Fix conflicts and add commit for modifications to complete merge:
git add README.md
git commit -m "merge track to master"
10.Check logs to see all commits present properly. Then push to remote:
git push origin master