Skip to content

Instantly share code, notes, and snippets.

@showaltb
Last active May 23, 2023 17:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save showaltb/d769db11cf67963e7a9a to your computer and use it in GitHub Desktop.
Save showaltb/d769db11cf67963e7a9a to your computer and use it in GitHub Desktop.
Show changed or untracked files in bash prompt

Here is how to have your bash prompt tell you if you have changed or untracked files in your working directory.

Add these lines to ~/.bash_profile:

source /usr/local/etc/bash_completion
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
export PS1='\u@\h \w$(__git_ps1) \$ '

(The location for bash_completion will vary; this is for OSX with homebrew installed git. The actual file you need is git-prompt.sh, which is distributed as part of git, but is copied by the installer to the bash_completion.d directory that bash_completion loads.)

The prompt for a clean working directory shows the current branch:

showaltb@Bobs-MBP ~/work/iq2-web (develop) $

A % character indicates untracked file(s):

showaltb@Bobs-MBP ~/work/iq2-web (develop) $ touch foo
showaltb@Bobs-MBP ~/work/iq2-web (develop %) $ git status
On branch develop
Your branch is up-to-date with 'origin/develop'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        foo

nothing added to commit but untracked files present (use "git add" to track)

A * character indicates changed or deleted file(s):

showaltb@Bobs-MBP ~/work/iq2-web (develop) $ rm README.md 
showaltb@Bobs-MBP ~/work/iq2-web (develop *) $ git st
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

      	deleted:    README.md

no changes added to commit (use "git add" and/or "git commit -a")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment