If you have created multiple repositories and now find it cluttered, you can merge them into a single repository while preserving all the commit history. Here’s how to do it.
Create a new repository on GitHub or locally on your machine.
git init new-repo
cd new-repoAdd the repositories you want to merge as remotes in the new repository.
git remote add repo1 <url-of-repo1>
git remote add repo2 <url-of-repo2>Fetch the commits from the other repositories.
git fetch repo1
git fetch repo2Create new branches for each repository to bring in the files.
git checkout -b branch-repo1 repo1/main
git checkout -b branch-repo2 repo2/mainMove the files from each branch to a subdirectory to avoid conflicts.
git checkout branch-repo1
mkdir repo1
git mv * repo1/
git commit -m "Moved repo1 files to subdirectory"
git checkout branch-repo2
mkdir repo2
git mv * repo2/
git commit -m "Moved repo2 files to subdirectory"Merge the branches into the main branch and resolve any conflicts that may arise.
git checkout main
git merge branch-repo1
git merge branch-repo2If you are using a remote repository, push the changes to it.
git remote add origin <url-of-new-repo>
git push -u origin mainSource: https://github.com/orgs/community/discussions/143759#discussioncomment-11167011
The code snippets were slightly modified.
Thank you to @abdulrahmanRadan