Skip to content

Instantly share code, notes, and snippets.

@blackfalcon
Forked from ivanoats/gist:1823034
Created April 10, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackfalcon/2352384 to your computer and use it in GitHub Desktop.
Save blackfalcon/2352384 to your computer and use it in GitHub Desktop.
Setting up GIT Bash autocompletion

Run the following to create ~/.git-completion.bash:

curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash > ~/.git-completion.bash

Then add the following to your ~/.bashrc or ~/.bash_profile after PATH:

# Set the base PS1
export PS1="\t: \W$ "

# Source the git bash completion file
if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
    GIT_PS1_SHOWDIRTYSTATE=true
    GIT_PS1_SHOWSTASHSTATE=true
    GIT_PS1_SHOWUPSTREAM="auto"
    PS1='\t:\[\033[32m\]$(__git_ps1 " (%s)")\[\033[00m\] \W$ '
fi

export PS1

This will display the branch name next to the folder name in the bash prompt.

Symbols after the branch name indicate additional information about the repo state:

  • *: The branch has modifications
  • $: There are stashed changes
  • =: The branch is equal with the remote branch
  • <: The branch is behind the remote branch (can be fast-forwarded)
  • >: The branch is ahead of the remote branch (remote branch can be fast-forwarded)
  • <>: The branch and remote branch have diverged (will need merge)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment