-
Notifications
You must be signed in to change notification settings - Fork 0
Git shell prompt
Distributed as part of the Git bash completion hook, the __git_ps1
function shows handy information about the current Git state in your prompt whenever you’re inside a Git checkout. For example:
user@hostname:~/dir (master *>)$
indicates that you’re on the master
branch with unstaged changes and also unpushed commits. Here are the meanings of various characters that might appear, and the configuration options that control them:
-
*
There are unstaged changes (shown withGIT_PS1_SHOWDIRTYSTATE
). -
+
There are staged but uncommitted changes (shown withGIT_PS1_SHOWDIRTYSTATE
). -
$
There is a stash (shown withGIT_PS1_SHOWSTASHSTATE
). -
%
There are untracked files (shown withGIT_PS1_SHOWUNTRACKEDFILES
—warning, this might slow down your prompt). -
>
There are local commits on HEAD that have not been pushed to its upstream branch (shown withGIT_PS1_SHOWUPSTREAM
). -
<
There are commits on the upstream branch that have not been merged to HEAD (shown withGIT_PS1_SHOWUPSTREAM
). -
<>
Both, i.e., HEAD and its upstream have diverged (shown withGIT_PS1_SHOWUPSTREAM
). -
=
HEAD points to the same commit as its upstream (shown withGIT_PS1_SHOWUPSTREAM
).
The ~/.bashrc
snippets below will load the Git bash prompt and insert Git state right before the last \$
in your PS1
. The first line may not be needed; most distros load __git_ps1
by default if bash completion is enabled. Modify as appropriate if your git-prompt.sh is not installed at $(git --exec-path)/git-sh-prompt
or if your PS1
does not use \$
.
. "$(git --exec-path)/git-sh-prompt"
PROMPT_COMMAND="$(printf '%q ' __git_ps1 "${PS1%%\\\$*}" "\\\$${PS1#*\\\$}");$PROMPT_COMMAND"
GIT_PS1_SHOWCOLORHINTS=t
GIT_PS1_SHOWDIRTYSTATE=t
GIT_PS1_SHOWSTASHSTATE=t
#GIT_PS1_SHOWUNTRACKEDFILES=t
GIT_PS1_SHOWUPSTREAM=git
. "$(git --exec-path)/git-sh-prompt"
PS1="${PS1/\\\$/\$(__git_ps1)\\\$}"
GIT_PS1_SHOWDIRTYSTATE=t
GIT_PS1_SHOWSTASHSTATE=t
#GIT_PS1_SHOWUNTRACKEDFILES=t
GIT_PS1_SHOWUPSTREAM=git
See the comments at the top of git-prompt.sh.