git branch help?

Thomas Spura tomspur at fedoraproject.org
Tue Aug 3 12:16:18 UTC 2010


Am Tue, 3 Aug 2010 11:44:02 +0200
schrieb Karel Zak <kzak at redhat.com>:

> On Tue, Aug 03, 2010 at 12:56:37PM +0530, Rahul Sundaram wrote:
> >  On 08/03/2010 12:53 PM, Peter Hutterer wrote:
> > > correct, git will share objects between branches, so by storing
> > > in different directories you'll loose that advantage.
> > >
> > > I've got a shell prompt that shows me the branch name whenever I
> > > enter a git directory so I don't have to worry about committing
> > > to the wrong branch.
> > 
> > For those wondering how,
> > 
> > http://blog.vagmim.com/2009/04/git-branch-on-command-prompt.html
> 
> This is pretty primitive implementation (do you really want to call
> python from $PS1? ;-)
> 
> The git package contains the /etc/bash_completion.d/git file where
> is defined function __git_ps1() which provides more usable strings
> (it's able to detect if you are rebasing, bisecting, merging, ...) and
> allows to use formatting for the string:
> 
>   $ echo $(__git_ps1 "git PS1 is: %s")
>   git PS1 is: master

Don't know why, but recently, that shows me "master" in any folder,
even when there is no git repository, so I switched my PS1 to something
similar from above:

function bash_git_branch
{
  git branch 2> /dev/null | grep \* | awk '{print $2}'
}

export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[31m\]
$(bash_git_branch)\[\033[01;34m\]\$\[\033[00m\] '

So no need to call python, if awk is enought :)

Host and username are green, directory blue and branch red now.

	Thomas


More information about the devel mailing list