CodeBlanks Logo Icon CodeBlanks

Summary - Checkout and switch

Combine checkout, switch and restore to manage branch changes.

Separate Branch and File Operations

In Git, switching branches and restoring files are different operations. In modern usage, git switch is preferred for changing branches, while git restore restores file contents. git checkout is the older multi-purpose command used for both tasks.

git switch surum
git restore aciklama.txt

Using these commands for their intended purposes makes your workflow clearer.

Practice Switch Branch and Restore a File

Switch to the release branch. Then restore description.txt in the working tree and print a completion message.

Starter code

terminal
print("Dal ve dosya işlemleri başlıyor")

Sample solution

terminal
git switch surum
git restore aciklama.txt
print("Dal değişti ve dosya geri yüklendi")

Expected output

Dal ve dosya işlemleri başlıyor
Dal değişti ve dosya geri yüklendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which modern pair of commands is appropriate for restoring a file and switching to another branch?

  • git remote and git push
  • git restore and git switch Correct answer
  • git branch and git merge
  • git status and git log

Explanation: Correct. git restore restores a file, while git switch changes branches.

2 Use the Revision Pointed to by HEAD

Question
git restore --source=____ aciklama.txt
Answer
git restore --source=HEAD aciklama.txt

Explanation: HEAD is a reference to the current position. The --source=HEAD option uses the file content at that position as the source.

3 Branch and File Management

Term Meaning
git checkout Operates on a branch or file
git switch Changes the active branch
git restore Restores file content
HEAD Points to the current revision

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow