git remove folder from repository keep local code example

Example 1: remove folder from repo but keep locally

git rm -r --cached File-or-FolderName
git commit -m "Removed folder from repository"
git push origin master

Example 2: git remove folder from repository

# the -r option will recursively delete the folder
git rm -r folder-name
# commit changes
git commit -m "Remove duplicated directory"

Example 3: git remove remote file keep local

# for single file
git rm --cached myfile

# for directory file
git rm --cached --r myfile