Find Branches Containing a Commit

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 a project. Sometimes, you may need to find out which branches contain a specific commit. This challenge will test your ability to use Git commands to find branches containing a commit.


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-12617{{"`Find Branches Containing a Commit`"}} end

Find Branches Containing a Commit

You have been given a Git repository named https://github.com/labex-labs/git-playground. Your task is to find all branches that contain a hash with the commit message "Added file2.txt".

Tasks

  1. Change into the repository directory.
  2. Find all branches that contain a hash with the commit message "Added file2.txt".

The output should be:

* master
new-branch
new-branch-1
new-branch-2

Summary

In this challenge, you learned how to find all the branches containing a specific commit using the git branch --contains command. This is a useful skill to have when working with Git repositories that have multiple branches.

Other Git Tutorials you may like