Introduction
In Git, branches are used to create different versions of a project. Switching between branches is a common task when working with Git. In this lab, you will learn how to switch to an existing branch in a Git repository.
In Git, branches are used to create different versions of a project. Switching between branches is a common task when working with Git. In this lab, you will learn how to switch to an existing branch in a Git repository.
You have been working on a project in a Git repository named https://github.com/labex-labs/git-playground
. Your team has created a new branch named feature-1
to work on a new feature. You need to switch to the feature-1
branch to continue working on the feature.
git clone https://github.com/labex-labs/git-playground.git
cd git-playground
git branch
Output:
feature-1
* master
feature-1
branch:git checkout feature-1
Output:
Switched to branch 'feature-1'
feature-1
branch:git branch
Output:
* feature-1
master
Switching to an existing branch in a Git repository is a common task when working with Git. Use the git checkout <branch>
command to switch to the specified branch. In newer versions of Git, you can also use git switch <branch>
.