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

  • SEARCH
  • Home
  • 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 691737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:35+00:00 2026-05-14T02:34:35+00:00

I want to be able to pass anything to a git command (maybe its

  • 0

I want to be able to pass anything to a git command (maybe its a SHA, maybe it’s just something like “origin/master” or “devel/epxerimental” etc.) and git tells me the ref path of the branch that the passed something lives in, e.g.

<git_command> 0dc27819b8e9 => output: refs/heads/master
<git_command> xyz/test => output: refs/remotes/xyz/master
...

I’ve been looking at git show or git log or git rev-parse and apart from --pretty=format:%d I couldn’t find anything.
(--pretty=format:%d output is quite strange with lotsa free space and empty lines and sometimes more than one ref paths are on one line bunched together).

There has to be a better way?

Thanks for reading.

Andre

  • 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-14T02:34:36+00:00Added an answer on May 14, 2026 at 2:34 am

    There is no fixed information which would record such a data, because SHA1 are not associated at all time with a ref path.
    Branches can moves, be renamed or deleted, while the SHA1 will still be stored (except if it is not referenced by any ref pattern, it will eventually be pruned)

    That being said:

    git show-ref |grep yourSHA1|awk "{print $2}"
    git show-ref --heads --tags -d |grep yourSHA1|awk "{print $2}"
    

    comes pretty close to what yout want:

    C:\Prog\Git\tests\rep\main5>git show-ref | grep f4a071 | awk "{print $2}"
    refs/heads/master
    refs/remotes/origin/HEAD
    refs/remotes/origin/master
    

    A lot of options are available for git show-ref and will allow you to:

    • display also dereferenced SHA1
    • display SHA1 only for a pattern of refs

    The OP adds:

    it will return nothing at all if a SHA passed does not reference a head or any other dereferencable commit?
    Do you have an idea how we could do the intermediary step of figuring out the SHA of the most recent commit belonging to the same branch as the SHA passed?

    One other plumbing command that can help would be git name-rev:

    C:\Prog\Git\tests\rep\main5>git name-rev a7768453
    a7768453 patches~1
    
    C:\Prog\Git\tests\rep\main5>git name-rev a7768453|gawk "{gsub(/~.*/,\"\",$2);print $2}
    patches
    

    As Jefromi mentions in the comments, a porcelain command would be git branch --contain:

    C:\Prog\Git\tests\rep\main5>git branch --contain 1e73e369
      master
    * patches
      tmp
    
    --contains <commit>
    

    Only list branches which contain the specified commit.
    It is used to find all branches which will need special attention if <commit> were to be rebased or amended, since those branches contain the specified <commit>.

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

Sidebar

Related Questions

I want to be able to pass a method as a parameter. eg.. //really
I'm playing around on GAE (I'm using Objectify) and wanted to make something like
I am sorry, that sounds like a noob question. I am trying to do
How can I pass a parameter to the method called by a NSTimer? My
Mootools Ajax class has a onComplete parameter whereby you can pass a function name
so i have a function for handling elements with a hover, however i want
I currently have a query that returns results based on a dynamic set of
I guess the title doesn't really say a lot, so here's the explanation. I
I'm working on a .net system that will both expose and consume web-services with
When I click a control with id of Button1 it calls a function called

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.