Use git rm
command:
git rm file1.txt
git commit -m "Remove file1.txt"
Use use the --cached
option:
git rm --cached file1.txt
git commit -m "Remove file1.txt from Git, but keep locally"
After committing, push the changes to the desired branch:
git push origin branch_name
To recursively remove all tracked files from the Git repo (without deleting them locally), run:
git rm -r --cached .
git commit -m "Remove all tracked files from Git, keep locally"
git push origin branch_name