Similarly to previous answers, I created ~/.config/ssh/git-prompt.sh file to change the behavior of the existing git-prompt.sh.
Content of the ~/.config/ssh/git-prompt.sh:
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title PS1="$PS1"'\n' # new line PS1="$PS1"'\[\033[32m\]' # change to green #PS1="$PS1"'\u@\h ' # user@host<space> #PS1="$PS1"'\[\033[35m\]' # change to purple #PS1="$PS1"'$MSYSTEM ' # show MSYSTEM PS1="$PS1"'\[\033[33m\]' # change to brownish yellow PS1="$PS1"'\w' # current working directory if test -z "$WINELOADERNOEXEC" then GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)" COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}" COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}" COMPLETION_PATH="$COMPLETION_PATH/share/git/completion" fi # comment out the line below to make it even faster, but you will not see the current branch PS1="$PS1 "'\[\033[35m\]`git branch --show-current 2>/dev/null`' # add branch in purple PS1="$PS1"'\[\033[0m\]' # change color PS1="$PS1"'\n' # new line PS1="$PS1"'$ ' # prompt: always $
Previous answers are using git branch and grep with sed, however from git 2.22 it's much simpler, just use the argument --show-current. This way it's simpler and it can be embedded inline in the prompt instead of depending on another function. It's easier to disable as well, just comment out one line.
In my script, I already commented out my user, host and system from my prompt.
You can run time command to benchmark to see which works best for you:
time git branch --show-current
And maybe you can compare it to the other alternatives posted here.
Maybe another alternative would be to disable as much fanciness as possible. And have custom .bashrc with a lot of aliases like alias gbr='git branch' or something in the lines. The prompt tries to be fancy, but if it's in a way of being usable then rather just call the shortcut of the branch alias command and have an overhead on every single command.
idcommand. If that takes a long time, ... I forget how you fix that, but it's at least something I've seen