git switch
- Git course
- Beginner
- Lesson 55/80
- 4 min
Learn to switch branches with git switch.
What is git switch?
git switch is a Git command that lets you move to the branch you want to work on. You can change the current branch by providing its name after the command. It is a clearer alternative to the older branch-switching use of git checkout.
git switch developmentAfter running the command, you are working on the development branch.
Switching branches and checkout
The modern approach to switching branches is to use git switch. Previously, git checkout branch-name was also used for the same purpose. However, since git checkout can also restore files, using separate commands makes the two operations clearer.
git switch main
git switch featureEach command makes the specified branch the current working branch.
Practice Switch to the specified branch
Write the command to switch to the previously created test branch. Then display the current branch using git branch.
Starter code
# test dalına geç
# Mevcut dalı gösterSample solution
git switch test
git branchExpected output
main * test
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command changes the current branch?
- git status
- git log
- git switch Correct answer
- git add
Explanation: The <code>git switch branch-name</code> command switches to the specified branch.
2 Switch to the main branch
git ____ main
git switch main
Explanation: The <code>git switch main</code> command changes the current working branch to main.
3 Branch switching concepts
| Term | Meaning |
|---|---|
git switch |
Switches branches |
current branch |
Currently active branch |
git checkout dal |
Older branch switching usage |
main |
Common primary branch name |