View Merged 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. After a branch has served its purpose, it is merged back into the main branch. However, it is important to keep track of which branches have been merged and which have not. This challenge will test your ability to view a list of all merged local branches.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/merge("`Merge Histories`") subgraph Lab Skills git/merge -.-> lab-12779{{"`View Merged Branches`"}} end

View Merged Branches

Your task is to print a list of all merged local branches in the Git repository named https://github.com/labex-labs/git-playground. You will need to use the command git branch -a --merged to display the list of merged branches. Once you have the list, you should be able to navigate through it using the arrow keys and exit by pressing Q.

  1. Navigate to the repository directory:
cd git-playground
  1. View the list of merged branches:
git branch -a --merged

This is the final result:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature-branch
  remotes/origin/master

Summary

In this challenge, you learned how to view a list of all merged local branches in a Git repository using the git branch -a --merged command. This is a useful tool for keeping track of which branches have been merged and which have not.

Other Git Tutorials you may like