Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 355177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:59:37+00:00 2026-05-12T11:59:37+00:00

How can I query git to find out which branches contain a given commit?

  • 0

How can I query git to find out which branches contain a given commit? gitk will usually list the branches, unless there are too many, in which case it just says “many (38)” or something like that. I need to know the full list, or at least whether certain branches contain the commit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:59:37+00:00Added an answer on May 12, 2026 at 11:59 am

    From the git-branch manual page:

     git branch --contains <commit>
    

    Only list branches which contain the specified commit (HEAD if not specified). Implies --list.


     git branch -r --contains <commit>
    

    Lists remote tracking branches as well (as mentioned in user3941992‘s answer below) that is "local branches that have a direct relationship to a remote branch".


    As noted by Carl Walsh, this applies only to the default refspec

    fetch = +refs/heads/*:refs/remotes/origin/*
    

    If you need to include other ref namespace (pull request, Gerrit, …), you need to add that new refspec, and fetch again:

    git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
    git fetch
    git branch -r --contains <commit>
    

    See also this git ready article.

    The --contains tag will figure out if a certain commit has been brought in yet into your branch. Perhaps you’ve got a commit SHA from a patch you thought you had applied, or you just want to check if commit for your favorite open source project that reduces memory usage by 75% is in yet.

    $ git log -1 tests
    commit d590f2ac0635ec0053c4a7377bd929943d475297
    Author: Nick Quaranto <nick@quaran.to>
    Date:   Wed Apr 1 20:38:59 2009 -0400
    
        Green all around, finally.
    
    $ git branch --contains d590f2
      tests
    * master
    

    Note: if the commit is on a remote tracking branch, add the -a option.
    (as MichielB comments below)

    git branch -a --contains <commit>
    

    MatrixFrog comments that it only shows which branches contain that exact commit.
    If you want to know which branches contain an "equivalent" commit (i.e. which branches have cherry-picked that commit) that’s git cherry:

    Because git cherry compares the changeset rather than the commit id (sha1), you can use git cherry to find out if a commit you made locally has been applied <upstream> under a different commit id.
    For example, this will happen if you’re feeding patches <upstream> via email rather than pushing or pulling commits directly.

               __*__*__*__*__> <upstream>
              /
    fork-point
              \__+__+__-__+__+__-__+__> <head>
    

    (Here, the commits marked ‘-‘ wouldn’t show up with git cherry, meaning they are already present in <upstream>.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've never used SimpleModal, but from the examples on their… May 12, 2026 at 11:00 pm
  • Editorial Team
    Editorial Team added an answer Having this declaration in the header: __declspec(dllexport) int fnunmanaged(void); __declspec(dllexport)… May 12, 2026 at 11:00 pm
  • Editorial Team
    Editorial Team added an answer Master edit: [btw, thank you for the accepted response.] In… May 12, 2026 at 11:00 pm

Related Questions

git log lists all commits, from all branches that have been merged into HEAD.
How can I query a particular website with some fields and get the results
how can I query an xml file where I have multiple items with the
How can I query all user defined data types from sql server like the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.