Ad space (banner)
🌿Git Lessons
Lesson 9 / 59

Switching Branches with git checkout

This lesson covers switching branches with git checkout. It's for anyone searching "git checkout switch branch."

git checkout switches which branch you're working on. Add the -b flag and it creates a new branch and switches to it in one step.

In Try It, run git checkout -b feature2. This creates a new branch called feature2 and immediately puts you in a state where you're ready to work on it.

A common early mistake is not accounting for unsaved changes on the branch you're switching away from — if changes aren't committed or stashed, the switch may not go smoothly. In real teams, creating a dedicated branch with git checkout -b every time you start a new feature is the basic workflow.

Git
Try it (type this into the pseudo terminal)
git checkout -b feature2

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)