CodeBlanks Logo Icon CodeBlanks

Summary - File lifecycle

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 → modified

You 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

terminal
# Dosyayı yeni adıyla taşı

Sample solution

terminal
# Dosyayı yeni adıyla taşı
git mv old-name.txt new-name.txt

Expected 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

Question
git mv draft.txt ____
Answer
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

All lessons in Beginner