git switch
- Git course
- Intermediate
- Lesson 6/82
- 4 min
Learn the modern branch switching with git switch.
The Modern Branch-Switching Command
In modern Git usage, git switch is preferred when you only want to change branches. It clearly expresses the intention to switch branches and separates this task from the multi-purpose git checkout command.
git switch developmentThe command changes the current branch. To restore file contents, use git restore.
Create and Switch to a New Branch
You can use git switch -c to create a new branch and switch to it at the same time. This option combines branch creation and switching in one command.
git switch -c yeni-arayuzWhen the command runs, the new branch is created and becomes the active branch. No separate creation command is needed.
Practice Create and Activate a New Test Branch
Create a new branch named test-otomasyon and switch to it with a single command. Then print a message confirming completion.
Starter code
print("Yeni test dalı hazırlanıyor")Sample solution
git switch -c test-otomasyon
print("Test otomasyon dalı etkin")Expected output
Yeni test dalı hazırlanıyor Test otomasyon dalı etkin
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command is preferred in modern Git when you only want to switch branches?
- git restore
- git status
- git diff
- git switch Correct answer
Explanation: Correct. git switch performs branch switching as a clear, dedicated command.
2 Create and Switch to a New Branch
git switch ____ deney
git switch -c deney
Explanation: The -c option creates a new branch and switches to it immediately.
3 Switch Command Options
| Term | Meaning |
|---|---|
git switch kalite |
Switches to an existing branch |
git switch -c |
Creates and switches to a new branch |
Dal değiştirme |
Changes the active working branch |
git checkout |
The older multi-purpose command |