Menu
Coddy logo textTech

Switching Branches

Part of the Version Control section of Coddy's Terminal journey — lesson 30 of 58.

Creating a branch and moving to it are two separate actions. The modern command for switching is git switch:

git switch feature-login

If you want to create and switch in one step, use the -c flag ("create"):

git switch -c feature-login

This is the most common workflow when starting new work.

You may also see git checkout in older tutorials. It does the same thing and still works:

git checkout feature-login
git checkout -b feature-login   # create and switch

To find out which branch you are on right now, run git branch --show-current:

git branch --show-current
feature-login
challenge icon

Challenge

Beginner

The repo has one commit on main. Create and switch to a new branch called experiment in a single command, then print the current branch name.

Cheat sheet

Switch to an existing branch:

git switch feature-login

Create and switch to a new branch in one step with -c:

git switch -c feature-login

Check which branch you are currently on:

git branch --show-current

Older equivalent using git checkout:

git checkout -b feature-login

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control