If I understand you correctly, you have two completely separate repositories, and you want to merge them, while keeping both commit histories. Is this correct? This is a bit tricky, but doable.
So you have your main repository (A) and want to include the whole history of another, completely separate repository (B) located in a subfolder of (A).
(Wherever I use (A) or (B), you should replace it with your actual repository names without those parentheses.)
Both repositories think, that their files live at the root of their working directory. They don't care, where those are on your computer. So you cannot simply push it in a directory and combine those two.
However, you can checkout (B) first, move everything inside a subfolder, and commit it.
Then, go to (A), add (B) as a remote (git remote add (B) path/to/(B)
) and merge them like so:
git fetch (B)
git merge (B)/main --allow-unrelated-histories
The --allow-unrelated-histories
argument is very important, so Git knows, that you intentionally wand to merge those separate repos.
If you have conflicts (Files, that were present in both repositories), you should be able to merge them manually and commit it afterwards, just like any other git conflicts.
Now you have the subfolder of (B) inside your (A) repository, and you may commit, modify and push like you want.