Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Last active February 26, 2026 13:41
Show Gist options
  • Select an option

  • Save tbnorth/6190181da468adf07afe9d66cc517a04 to your computer and use it in GitHub Desktop.

Select an option

Save tbnorth/6190181da468adf07afe9d66cc517a04 to your computer and use it in GitHub Desktop.
Fast Git Bash (Windows) git status prompt
# Paste this at end of .bashrc
# Replacing "On branch" with " " makes sure the branch-name sorts first in `sort -u`
# sort -u removes duplicate x!? chars. for multiple deleted / modified / unknown files
# final sed strips leading space and linebreaks and adds []
function fast_git_ps1 {
git status 2>&1 | sed -En '
/On branch/ {s/On branch / /; s/$/ /; H}
/deleted:/ {s/.*/x/; H}
/modified:/ {s/.*/!/; H}
/Untracked files/ {s/.*/?/; H}
/ahead of/ {s/.*/*/; H}
/behind/ {s/.*/</; H}
/dubious ownership/ {s/.*/ERR:see git status/; H}
$ {x; p}' | sort -u | sed -En 's/^ //; H; $ {x; s/\n//g; s/^/[/; H; s/ ?$/]/; s/\[]//; p}'
}
PS1="${PS1/__git_ps1/fast_git_ps1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment