Using .gitignore you can specify files and folders that should not be uploaded to the git repository.
But sometimes it happens that you upload / push all files to the git repo first and then realize that some of the folders should not be in the repo.
First you put this folder in the .gitignore and then you can use the following command to delete the folder from the repo. This will keep the folder on your machine and only delete it from the git repo.
git rm -r --cached my-folder
git commit -m 'Delete the now ignored folder "my-folder"'
git push origin master
All new changes in the folder will be ignored by git from now on. The next time you staging and push, the folder will no longer be present in the new git push.