You want to remove a file from the current working tree and use git add --all safely. It is removed completely from file system as well. For that, we use git rm --force but it doesn't apply to "untracked" files. For more information, click git rm link.


Check the current status


inanzzz@inanzzz:~/project$ git status
On branch develop
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: file_four.txt
new file: file_three.txt

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: file_two.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)

file_one.txt

Remove file from working directory


inanzzz@inanzzz:~/project$ git rm --force file_three.txt
rm 'file_three.txt'

Check the current status


As we can see, "file_three.txt" is not in working directory anymore and git add --all can be used safely however if you do any updates to the file, it will appear in "untracked" section.


inanzzz@inanzzz:~/project$ git status
On branch develop
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: file_four.txt

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: file_two.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)

file_one.txt

Commit


As we can see, only three files have been committed.


inanzzz@inanzzz:~/project$ git add --all
inanzzz@inanzzz:~/project$ git commit -m 'Commit'
[develop 860fcb2] Commit
3 files changed, 8 insertions(+)
create mode 100644 file_one.txt