Skip to content

Instantly share code, notes, and snippets.

@mhaylock
Created May 6, 2011 03:14
Show Gist options
  • Save mhaylock/958381 to your computer and use it in GitHub Desktop.
Save mhaylock/958381 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
PS1="\h:\W \u\$ "

# 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='\h:\[\033[32m\]$(__git_ps1 " (%s)")\[\033[00m\]\W \u\$ '
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 staged changes
  • $: 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)
@Cdxdcdxdcd
Copy link

[https://gist.github.com/mhaylock/958381?permalink_comment_id=4414116#gistcomment-4414116]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment