When searching how to create a branch from an existing git repository, I found the unanswered Discussion #33549 on GitHub. Here’s how I merged two repositories into one, also commented on said Discussion.
Let’s say I have two repositories main
and other
both with a branch main:
cd main
Add other repository as a remote and fetch it’s main
branch, creating the ref other/main
git remote add other ../other
git fetch other main
Create new branch called other
for the fetched code and optionally push new branch to the regular remote.
git checkout other/main -b other
git push -u origin other
Now you have branch main with your original code and branch other containing the code from the others’ main branch. If that’s the only branch in the other repository, you could delete it now.