How do you remove a file from both the working directory and Git index?

How do you remove a file from both the working directory and Git index?

a) git delete file
b) git rm file
c) git remove file
d) git reset file

Answer:

b) git rm file

Explanation:

The git rm file command removes a file from both the working directory and the Git index (staging area). This means the file will no longer be tracked by Git, and it will also be deleted from your local file system.

For example, running git rm filename will stage the file for deletion in the next commit and remove it from your local directory.

Use this command when you want to permanently remove a file from the project and stop tracking it in future commits.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top