Deleting a file

If you don't mind the file being present in Git history:

git rm <file> # This is same as deleting locally and staging
git rm --cached <file> # Delete from git tracking, but keep file locally

# To undo this
git restore --staged <file>
git restore <file>

If you need to rewrite the Git history as well:

# Remove from last commit
git rm --cached <file>
git commit --amend

# Remove from older commits
git filter-branch --tree-filter 'rm -f <file>' HEAD

# Remove from entire history (See note below.)
git filter-repo --invert-paths --path <path-to-file>

# Rebase to remove commits
git rebase -i <commit-hash>^
# In editor, delete lines with unwanted commits

# Force push
git push --force

Note: filter-repo must be manually installed.