Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tomdwp/561051943a69e334cc8d7694bb56eebd to your computer and use it in GitHub Desktop.
Save tomdwp/561051943a69e334cc8d7694bb56eebd to your computer and use it in GitHub Desktop.
Setting up GIT Bash autocompletion. Use this only if you are using Bash instead of ZSH.

To see what shell you are using, you can:

echo $SHELL and it will tell you.

Use the below only if you are using bash.

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

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

and ~/.git-prompt.sh:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh > ~/.git-prompt.bash

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

# Source the git bash completion file
if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
fi
# Source the git bash prompt file  -- note part changes your existing bash prompt (would be nice to re-work)
if
    source ~/.git-prompt.bash
    export GIT_PS1_SHOWDIRTYSTATE=true
    export GIT_PS1_SHOWUNTRACKEDFILES=true
    export GIT_PS1_SHOWCOLORHINTS=true
    export PROMPT_COMMAND='__git_ps1 "\w" "\\\$ "'

   fi

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