I have followed http://blog.bitfluent.com/page/3 to add git-completion.bash to my /opt/local/etc/bash_completion.d/git-completion

and I put PS1='\h:\W$(__git_ps1 "(%s)") \u\$ ' in my .bashrc_profile

But now I am getting this -bash: __git_ps1: command not found everything I do a cd.

Can you please tell me what am I missing?

link|improve this question

64% accept rate
feedback

6 Answers

up vote 26 down vote accepted

I installed git using MacPorts on my new Snow Leopard installation. After MacPorts is installed from the .dmg image, these would be the commands in Terminal.app:

sudo port selfupdate
sudo port install git-core +bash_completion

If you also want support for pulling from SVN repositories and docs, use this instead of the second line:

sudo port install git-core +bash_completion +doc +svn

Then add the following to your ~/.profile or ~/.bash_profile:

# MacPorts Bash shell command completion
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi
link|improve this answer
Thank you, that definitely helped! – NiKo Apr 30 at 12:03
feedback

All you need to do is place the git-completion.bash file in your user home bin directory and place the following in you .profile or .bash_profile file:

export PATH="$HOME/bin:$PATH"
source ~/bin/git-completion.bash
PS1='[\u@\h \w$(__git_ps1 " (%s)")]\$ '

What this does is make sure that your local bin is in the PATH and the source command gets things going. Then of course the PS1 change puts the currently checked out branch in the prompt.

So, no MacPort install to then install a the "completion" version of GIT (especially irritating if you already have it installed).

link|improve this answer
1  
For those wondering how to combine that PS1 thing with colors in your prompt see: stackoverflow.com/questions/816790/… – Nickolay Jan 10 '11 at 12:11
More precisely, git-completion.bash just needs to be somewhere in your $PATH. I decided to put mine in /usr/local/bin/ so that I didn't have to modify my existing $PATH. – metavida Jul 11 '11 at 18:07
feedback

If you installed git using homebrew than you might adjust the MacPorts advice a little and add this to your .bashrc

if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then
. `brew --prefix`/etc/bash_completion.d/git-completion.bash
fi

The best way to check if you have git correctly installed using homebrew ist to execute

brew info git

and check the output for the install directory of the git bash completion

link|improve this answer
feedback

You need to source the command completion functions. Add to your .bashrc_profile before the PS1:

. /opt/local/etc/bash_completion.d/git-completion
link|improve this answer
feedback

I think you maybe forget sourcing the file in your loged .bashrc

link|improve this answer
feedback

In addition to Adam K. Johnson's post

You can also put the following...

# MacPorts Bash shell command completion
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi

...in your /etc/profile, if you want.

That way all users on the system will benefit from any bash completion scripts installed in the directory "/opt/local/etc/bash_completion.d/".

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.