Git Command Prompt

A super-useful little .bash_profile tweak to bring context to git and git-flow

  • Git Flow. Awesome
    Git Flow. Awesome

I take no credit for this genius little bit of code but if you're using git, or the brilliant git-flow here's a few lines to add to your .bash_profile to bring you command-line usage of git to life.

Basically all it does it stick the current branch into your command prompt for you.

spirit@develop $ git flow feature start foo

To get this fired up just add the following four lines to your bash profile.  You can find this in ~/.bash_profile

parse_git_branch() {
      git branch --no-color 2> /dev/null | fgrep '*' | sed 's/* //'
export PS1="\W@$(parse_git_branch) $ "

And there you have it.  

Next time you log in you'll have a new command prompt.  To load up the new prompt right away you can use 'source' (Thanks to @zackkitzmiller for showing me this bit).

# source ~/.bash_profile 

Done? Great.  

Credit to @philsturgeon for finding this script.


1 Comments on this post