how to delete file from git code example

Example 1: delete file from a branch git

git rm --cached file1.txt
git commit -m "remove file1.txt"

Example 2: how to delete file from git command

git rm file1.txt
git commit -m "remove file1.txt"

Example 3: how to delete file from git command

git rm --cached file1.txt
git commit -m "remove file1.txt"

Example 4: remove git deleted files

git add .  => Add all (tracked and modified)/new files in the working tree.

git add -u => Add all modified/removed files which are tracked.

git add -A => Add all (tracked and modified)/(tracked and removed)/new files in the working tree.

git commit -a -m "commit message" - Add and commit modified/removed files which are tracked.