How To Setup Git Completion And Repo State On Osx (Like A Pro)

I spent some time recently helping two of my students set up some Git tools on their systems, which proved rather difficult. Information was spotty on the internet, and due to the variety of system configurations, it was impractical to download Xcode, install HomeBrew, and so forth. I thought it was time to layout how we did it, quite simply, and also admonish that all Git users to set something similar up.

Every Git User Should Do This

I personally think that if you ever point someone else at something in your terminal, it is nice to have a reasonable prompt that helps convey some information. Also, who wants to type git status -s over and over and OVER again?

1. Create the files you need

touch ~/.bash_profile
touch ~/.git-completion.bash
touch ~/

2. Populate your completion file

In the .git-completion.bash file put the contents located here:

Update the permissions of the file (not sure if this is necessary).

chmod 755 ~/.git-completion.bash

3. Populate your prompt file

In the file, put the contents located here:

Update the permissions of the file (not sure if this is necessary).

chmod 755 ~/

4. Populate your .bash_profile

You may already have things in this file; if so, you may add this to the bottom or top:


source ~/.git-completion.bash
source ~/

export LS_OPTIONS='--color=auto'
export CLICOLOR='Yes'
export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD

export PS1=$LIGHT_GRAY"\u@\h"'$(
    if [[ $(__git_ps1) =~ \*\)$ ]]
    # a file has been modified but not added
    then echo "'$YELLOW'"$(__git_ps1 " (%s)")
    elif [[ $(__git_ps1) =~ \+\)$ ]]
    # a file has been added, but not commited
    then echo "'$MAGENTA'"$(__git_ps1 " (%s)")
    # the state is clean, changes are commited
    else echo "'$CYAN'"$(__git_ps1 " (%s)")
    fi)'$BLUE" \w"$GREEN": "

alias ll='ls -lah'
alias gg='git status -s'

5. Reset your terminal

Now, you should have a few things going for you:

  • Clean looking path prompt.
  • Indication of the branch you are on in a Git repository.
  • gg now gets you your git status -s.
  • ll gives you an ls -lah (file list all, long, human readable).
  • Sweet color changes and symbols on repo state change.

Everything is fine and dandy and my repo is in a clean state!

Clean state prompt.

It looks like I must have added some files.

Files added prompt.

There are files added, but also modified.

Files modified prompt.

Something has been modified, but not added.

Modified, but not added prompt.

If you enjoyed reading this or learned something, please consider sharing via , , or . Thanks!

If you enjoyed this article, you might like others related to the Software interest.