Deleting (git rm)
- Git course
- Beginner
- Lesson 43/80
- 4 min
Learn to delete files with git rm.
Delete files with git rm
The git rm command removes a tracked file from the working directory and stages the removal. This prepares the deletion for the next commit. The command updates both the working copy and Git's tracking information.
git rm old-notes.txt
git statusYou can commit the removal to record it in Git history.
Commit the removal
After running git rm, the deletion is staged. You can use git status to check the change. Then create a commit to record the file removal in the project history.
git rm draft.txt
git status
git commit -m "Remove draft"A commit stores the deletion in history just like other changes.
Practice Remove a tracked file
Write the command that deletes the tracked temporary.txt file and stages its removal.
Starter code
# Dosyayı kaldır ve silme işlemini sahneleSample solution
# Dosyayı kaldır ve silme işlemini sahnele
git rm temporary.txtExpected output
git rm temporary.txt
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command deletes a tracked file and stages the removal at the same time?
- git rm old-notes.txt Correct answer
- git status old-notes.txt
- git log old-notes.txt
- git add old-notes.txt
Explanation: <code>git rm</code> removes the tracked file and stages the deletion.
2 Remove the file and stage its deletion
git _______ obsolete.txt____
git _______ obsolete.txtrm
Explanation: <code>git rm obsolete.txt</code> removes the file and stages its deletion.
3 File deletion process
| Term | Meaning |
|---|---|
git rm |
Deletes the file and stages removal |
Delete |
Removal of a file |
git status |
Displays the deletion state |
git commit |
Records the deletion in history |