GIT bash cheats

When you install GIT you should also install the GIT bash completion with it. (On gentoo you just need to set the bash-completion USE flag when emerging git). This makes your life much easier. This can complete git commands like “git stat[TAB]” to “git status”. Additionally it offers the GIT bash function __get_ps1 for your command prompt. You can integrate this into your “PS1″ variable to show the current branch of your working dir on your command prompt. That’s just great, isn’t it?

Add this to your ~/.bashrc to activate the GIT bash completion and the new command prompt.

# load git bash completion
source /usr/share/bash-completion/git
# Cool trick to show current git branch in the command prompt in gentoo colors.
export PS1='\[33[01;32m\]\u@\h\[33[01;34m\] \w$(__git_ps1 " (%s)") \$\[33[00m\] '

If you enter your working dir the prompt will look like this.

gergap@lt_gergap ~/work/helisim (master) $

If you are wondering what this “\[33...]” is for, this is just to set some nice colors for the prompt. You can remove that if you don’t like colors.

~ by gergap on July 9, 2009.

Leave a Reply