Skip to content

Instantly share code, notes, and snippets.

@aruprakshit aruprakshit/bash_git.md
Last active Aug 29, 2015

Embed
What would you like to do?
Git and Bash shell customizations

Get the git-promt.sh script here. Put it somewhere like ~/.git-prompt.sh. If you want to be all CLI about it, you could just run:

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

Now modify your your bash profile (it’s at ~/.bash-profile, in case you’re new to this stuff). Before the part of the file that declares what your prompt will look like (PS1=[...]), load in the script you just downloaded, like so:

# Load in the git branch prompt script.
source ~/.git-prompt.sh

Now add \$(__git_ps1) to your prompt declaration. You can put it wherever you like, but I think it’s best suited for the very end, right before the final dollar sign (\$) If you want to get all _fancy, you can make it a pretty color. My declaration looks like this:

PS1="\[$GREEN\]\t\[$RED\]-\[$BLUE\]\u\[$YELLOW\]\[$YELLOW\]\w\[\033[m\]\[$MAGENTA\]\$(__git_ps1)\[$WHITE\]\$ "

(See here for color definitions.)

This declaration results in a prompt looks like this when I’m in the directory ~/src/food52 and on the branch develop:

@aruprakshit

This comment has been minimized.

Copy link
Owner Author

aruprakshit commented Feb 23, 2015

Copied from this blog.. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.