One way is to use rm -rf *, which will delete all files from the folder except the dotfiles and foldersdotfolders like .git. You can then delete the dotfiles and dotfolders one by one, so that you don't miss out on anyimportant dotfiles like .gitignore or, .gitattributes or any other important dotfile later.
Another approach would be to move your .git folder out of the directory and then going back and deleting all the contents of the folder and moving the .git folder back.
mv .git/ ../ cd .. rm -rf folder/* mv .git/ folder/ cd folder