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 7657679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:05:13+00:00 2026-05-31T13:05:13+00:00

So I know this question have been asked a lot , but I don’t

  • 0

So I know this question have been asked a lot, but I don’t find any suitable answers. I’m looking to display the name of the current git rev in my prompt, but in a pretty way : if I’m on a branch, I want the name of the branch; if it’s not a branch, I’d like the relative name (ie master~2) in my prompt.

At first, I was using something like what you can see here. It worked well : I had the name of the branch, or the rev SHA1 number. Then I moved to an approached based on git name-rev, which was great at first, but then I noticed that the name was mixed up sometimes : after merging master into staging, on both branches I had master in my prompt. Given how much I rely on this, I can’t have this. But having master~2 instead of a SHA1 number was really great.

So I hope there’s a way to combine both approaches. If it’s possible to display the tag name too, I’ll take it (though I don’t use them much – yet). And the top would be to have git only commands, no looking up git internal files — they could change at some point.

Thanks for reading!

  • 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-31T13:05:14+00:00Added an answer on May 31, 2026 at 1:05 pm

    Taken from zsh-git repository: https://github.com/jcorbin/zsh-git/blob/master/functions/zgitinit#L70

    name=$(git symbolic-ref -q HEAD)
    if [ $? -eq 0 ]; then
        if [[ $name == refs/(heads|tags)/* ]]; then
            name=${name#refs/(heads|tags)/}
        fi
    else
        name=$(git name-rev --name-only --no-undefined --always HEAD)
        if [ $? -ne 0 ]; then
            return 1
        elif [[ $name == remotes/* ]]; then
            name=${name#remotes/}
        fi
    fi
    

    You may also consider using zsh 🙂

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

Sidebar

Related Questions

I know this question already have been asked. But I could not find any
Hi I know this question have been asked before but the answers there isn't
I know similar permutations of this question have been asked before, but the answers
I know this question have been asked endless times but I can't find a
I know variants of this question have been asked before (even by me), but
I don't know if this question has been ask before. But I have a
I know this question would have been asked several time but still I am
I know that this question have been asked several times. But I can't get
I know a lot of question regarding VB6 migration have been asked, but I
I thought this question would have been asked before, but I couldn't find it

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.