Summary - File lifecycle
- Git course
- Beginner
- Lesson 44/80
- 5 min
Combine lifecycle steps to explain a file's journey.
The Git file lifecycle
When a file is created, it may initially be untracked. After using git add, Git starts tracking it; when committed, its version is recorded in history. Later edits create the modified state.
New file → git add → commit
Tracked file → modifiedYou can use Git file commands to remove or rename files.
Practice Rename a file
Rename the tracked old-name.txt file to new-name.txt. Write the appropriate command so Git stages the change.
Starter code
# Dosyayı yeni adıyla taşıSample solution
# Dosyayı yeni adıyla taşı
git mv old-name.txt new-name.txtExpected output
git mv old-name.txt new-name.txt
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command do you use to rename a tracked file while preserving Git's file history?
- git log
- git mv Correct answer
- git diff
- git status
Explanation: <code>git mv</code> moves a file to a new location or name and stages the change.
2 Move a file to a new name
git mv draft.txt ____
git mv draft.txt final.txt
Explanation: <code>git mv draft.txt final.txt</code> renames the file and stages the change.
3 Operations in a file's lifecycle
| Term | Meaning |
|---|---|
Untracked |
A file not yet tracked |
Tracked |
A file monitored by Git |
git rm |
Deletes a file and stages removal |
git mv |
Moves or renames a file |