View Local Branches

GitGitBeginner
Practice Now

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

Introduction

In Git, branches are used to develop features or isolate changes made to the codebase. Local branches are the branches that exist only on your local machine. In this challenge, you will learn how to view a list of all local branches in a Git repository.


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-12769{{"`View Local Branches`"}} end

View Local Branches

You have been working on a Git repository named https://github.com/labex-labs/git-playground. You want to view a list of all local branches in the repository.

  1. Navigate to the cloned repository using the following command:
    cd git-playground
  2. Use the following command to view a list of all local branches:
    git branch
    You will see a list of all local branches in the repository. Use the arrow keys to navigate through the list and press Q to exit.

This is the final result:

Summary

In this challenge, you learned how to view a list of all local branches in a Git repository. Using the git branch command, you can easily view all the branches that exist on your local machine. This can be useful when you need to switch between branches or merge changes from one branch to another.

Other Git Tutorials you may like