OS X Git Prompt

I’m currently using a modified version of git-prompt that looks something like this:

Git-prompt

If you want to try it out, you can download this zip-ball:

git-prompt.zip

Unpack that into your User folder, and add this to your bash .profile:

# Git Prompt - Modified from: http://volnitsky.com/project/git-prompt/
[[ $- == *i* ]] && . ~/git-prompt/git-prompt.sh

Tip: You can open your .profile from your terminal like so:

open ~/.profile

Note: You will need to start a new shell session after editing that file in order to see the changes.

I use Nano as my default bash text editor. If you want that, add this to your .profile:

# Use the nano text editor
export EDITOR="nano"

And for the Terminal.app style:

Terminal-prefs

Power-User-Pro.terminal.zip

The shell commands (copy-paste):

mkdir Test
cd Test/
git init
touch somefile
git add somefile
git commit -m "commit message"
echo "hi" > somefile
git add somefile
git commit -m "second commit"
git checkout -b temp
echo "hello" > somefile
git add .
git commit -m "3rd commit"
Posted in Resources, Tutorials | Tagged , , , , | 7 Comments
  • alecmce

    Hi Shaun,

    Thanks for this. I had quite a few problems getting it to work for me, which was frustrating. In the end I went into my Terminal/preferences/startup and switched the “Shell opens with” from /usr/bin/login to /bin/bash. Then I saved my .profile file (with modifications as above) to .bash_profile. Finally, on restarting my terminal, it worked.

    I've never mucked around with bash so I was pretty much in the dark, and getting it to work is dumb luck.

    In any event, thank you for introducing me to the GIT Prompt project; this is going to come in very handy!

  • http://shaun.boyblack.co.za/blog/ shaun

    Hmm.. I'm sorry to hear that you had trouble with it. I'm pretty new to all this myself. My Terminal is still set to /usr/bin/login. It might have something to do with how git is installed: port vs installer vs manually compiling it. Also, I should definitely have mentioned that you need to start a new Terminal session after editing the .profile!

  • http://omita.com/ Hays

    Awesome. This rocks.

  • Pingback: git on the command line « Ramblings

  • http://alecmce.com alecmce

    Shaun, I'm in the process of setting up a new machine, and was doing all this again. This time I had few problems with the .profile, if I used ~/.bash_profile instead. Anyway, I did have problems with the script however:

    -bash: eval: line 9: syntax error near unexpected token `||'
    -bash: eval: line 9: `|| return'

    coming from line 60 of git-prompt.sh. Now that's doubly weird because I checked the original source on volnitsky.com, and the only difference as far as I can see is that you've tweaked the formatting. I don't understand why this should throw errors for me, but not for anyone else?!

    Any pointers would be appreciated. If not, I'll keep looking. Cheers.

  • http://alecmce.com alecmce

    It happens if you haven't installed git yet. :-S

  • http://shaun.boyblack.co.za/blog/ shaun

    Hahahaa! Gotta hate it when that happens!

    I seem to remember that I changed the formatting in order to prevent similar errors – it's possible that the script contains strange (hidden) characters. I found that by stripping out a bunch of white-space (and possibly more) I managed to get it to work, but I left it at that.