In the end none of these answers worked for me.
OP specifically wants "no loss of git history".
Most of these answers blow away git history.
I found the answer on another thread, specifically the answer that says to use "git mv" command, which I was not aware of.
Move file and directory into a sub-directory along with commit history
- To move tracked files, use "git mv".
- To move untracked files, just
move them using "mv".
This process preserves all your history, including uncommitted changes. No need for a clean working copy.
So to answer OPs question,
Starting out in the original folder, make another folder with the same name!
$ /Users/me/gitrepo1> mkdir gitrepo1
$ /Users/me/gitrepo1> ls
.git/
.gitattributes
.gitignore
gitrepo1/
exampleFile
exampleDir/
exampleUntrackedFile
$ /Users/me/gitrepo1> git mv exampleFile exampleDir gitrepo1
$ /Users/me/gitrepo1> git mv exampleUntrackedFile gitrepo1
fatal: not under version control, source= exampleUntrackedFile, destination= gitrepo1/exampleUntrackedFile
$ /Users/me/gitrepo1> mv exampleUntrackedFile gitrepo1
$ /Users/me/gitrepo1> git status
renamed: exampleFile -> gitrepo1/exampleFile
renamed: exampleDir -> gitrepo1/exampleDir
Untracked files:
gitrepo1/exampleUntrackedFile
And finally, rename to newrepo
cd ..
mv gitrepo1 newrepo