Sometimes, we want to show current git branch in Bash prompt. git symbolic-ref --short -q HEAD
is too slow, especially in WSL. Here is a pure Bash version to print git branch.
function _get_git_branch() {
local _head_file _head
local _dir="$PWD"
while [[ -n "$_dir" ]]; do
_head_file="$_dir/.git/HEAD"
if [[ -f "$_dir/.git" ]]; then