Create a New Branch (Challenge)

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

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 challenge, 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-12628{{"`Create a New Branch (Challenge)`"}} end

Create a New Branch

For this challenge, 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.

Tasks

  1. Clone the repository, navigate to the directory and configure the identity.
  2. Check the current branch.
  3. Create a new branch named feature-1.
  4. Verify that you are now on the feature-1 branch.
  5. Push the changes to the remote repository.

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.

Other Git Tutorials you may like