🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
In Git, a branch is a lightweight movable pointer to a commit. Creating a new branch allows you to work on a new feature or bug fix without affecting the main codebase. In this lab, you will learn how to create a new branch in Git.
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
git(("Git")) -.-> git/BranchManagementGroup(["Branch Management"])
git/BranchManagementGroup -.-> git/branch("Handle Branches")
subgraph Lab Skills
git/branch -.-> lab-12714{{"Create a New Branch"}}
end
Create a New Branch
For this lab, fork the Git repository named https://github.com/labex-labs/git-playground into your GitHub account.You are working on a project in a Git repository named https://github.com/your-username/git-playground. You need to create a new branch named feature-1 to work on a new feature.
Clone the repository, navigate to the directory and configure the identity:
This is what happens when you run the git branch -r command:
Summary
Creating a new branch in Git is a simple process that allows you to work on a new feature or bug fix without affecting the main codebase. Use the git checkout -b <branch> command to create a new branch with the specified name and switch to it. You can optionally add -t <remote>/<branch> to set up a remote tracking branch for the newly created branch.