Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. How to use Git
  6. How to use branching in Git
  7. Switch to a branch
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Switch to a branch

Switching branches is a fundamental operation in Git that allows you to move between different lines of development seamlessly. By switching branches, you can shift your focus to a particular feature, bug fix, or experiment, while leaving the rest of the codebase undisturbed. This flexibility enables efficient collaboration and independent progress on multiple fronts within the project.

In this part of our tutorial, we will guide you through the process of switching between branches in Git, allowing you to seamlessly transition to the branch of your choice and continue development on a specific line of work.

You just created a branch now you'll need to switch to that branch to add new commits to it.

Use the git checkout command to switch to the branch issue1.

$ git checkout issue1
Switched to branch 'issue1'

Now, the history looks like this:

Current history

Use the -b option to create a new branch and switch to it with one command.

Next, let’s add a commit. Add the bold text below to the myfile.txt file.

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index

And commit the change.

$ git add myfile.txt
$ git commit -m "append description of the add command"
[issue1 b2b23c4] append description of the add command
 1 files changed, 1 insertions(+), 0 deletions(-)

The history now looks like this:

Current history

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life