CodeBlanks Logo Icon CodeBlanks

git switch

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 development

After 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 feature

Each 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

terminal
# test dalına geç

# Mevcut dalı göster

Sample solution

terminal
git switch test
git branch

Expected 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

Question
git ____ main
Answer
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

All lessons in Beginner