Skip to content

Instantly share code, notes, and snippets.

@hack0001
Forked from ivanoats/gist:1823034
Created January 23, 2019 23:59
Show Gist options
  • Save hack0001/c2708610d5dc2af9986e3385455238a0 to your computer and use it in GitHub Desktop.
Save hack0001/c2708610d5dc2af9986e3385455238a0 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.github.com/git/git/master/contrib/completion/git-completion.bash > ~/.git-completion.bash

and ~/.git-prompt.sh:

curl https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.git-prompt.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
    source ~/.git-prompt.bash
    PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
fi

export PS1

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

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