Instantly share code, notes, and snippets.

What would you like to do?
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 > ~/.git-completion.bash

and ~/

curl > ~/.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)")]\$ '

export PS1

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


This comment has been minimized.

Copy link

vsee commented Feb 24, 2017

nice piece of code! There is one bug I saw: the second file is called but in bashrc sourced as .git-prompt.bash


This comment has been minimized.

Copy link

rbrisita commented Jan 20, 2018

To future proof use curl's '-L' option to follow redirects. In its current form the curls won't work on Mac OS X.


This comment has been minimized.

Copy link

gzalles commented Jan 23, 2018

can you help me with the path? I have managed to get color scheme and branch showing but not the autocomplete. Thanks!

new to this game...

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