From c6cc2f3160d3265ba09dab0f2040340b5d283c38 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Thu, 19 Oct 2023 15:43:54 +0100 Subject: [PATCH] Update way to get branch name in git repo. --- .bashrc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.bashrc b/.bashrc index 4628619..c1febf8 100644 --- a/.bashrc +++ b/.bashrc @@ -55,11 +55,12 @@ __prompt_git_status() { } # Add the branch or a no commits marker. - BRANCH="$(git describe --contains --all HEAD 2>/dev/null)" - if [[ -n "$BRANCH" ]]; then - GIT_PROMPT+="$BRANCH" - else + BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" + if [[ "$BRANCH" == "HEAD" ]]; then GIT_PROMPT+="!NO COMMITS!" + unset BRANCH + else + GIT_PROMPT+="$BRANCH" fi # Add upstream status.