Last active

Creating a Happy Git Environment on OS X

  • Download Gist

Creating a Happy Git Environment on OS X

Step 1: Install Git

Configure things:

git config --global "Your Name"
git config --global ""
git config --global checkout
git config --global apply.whitespace nowarn

Setup an SSH key


Hit return a couple of times -- leave password blank if you want.

cat ~/.ssh/ | pbcopy

Paste that code into your settings page on your repository host(s).

Get happy Git colors. Paste the following into your ~/.gitconfig file:

    branch = auto
    diff = auto
    status = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan

Create a ~/.gitexcludes file and paste in this:


There, now you don't have to ignore that every time.

Bash Fanciness

Add the following to your ~/.bash_profile or ~/.bashrc:

source /usr/local/git/contrib/completion/git-completion.bash
export PS1='[\u@mbp \w$(__git_ps1)]\$ '

That will add tab auto-completion for Git branches, display the current branch on your prompt, and show a '*' after the branch name if there are unstaged changes in the repository, and a '+' if there are staged (but uncommitted) changes. It will look something like this:

[user@computer ~/Sites/ (master*)]$ 


If you want to have a different email address for a particular project (a personal project on your work computer, perhaps?), just run this command inside that project's folder:

git config ""

It's the same command as before, this time just omitting the --global.


I'm not sure these bits are still needed:

git config --global github.user [your_username]
git config --global github.token [your_token]

Mine works fine without them. Also see ("Set your GitHub token").

Thanks, @geoffalday! I removed that bit.

The checkout appears to be unnecessary, at least on my install of via Homebrew (brew install git). It's the only alias that's there by default.

Also, thanks for this! It has been a big help and I've used it a bunch of times while setting up new systems.

Oh, also, when installing git via Homebrew (brew install git) and using the git in /usr/local/bin, the bash completion line in the Bash Fanciness section should be changed from:

source /usr/local/git/contrib/completion/git-completion.bash


source /usr/local/etc/bash_completion.d/git-completion.bash

I am on OSX 10.8.2
I needed to source to get the "show branch" to work, i.e. add this to your .bashrc or .bash_profile:

source /usr/local/git/contrib/completion/

On 10.9 / Xcode 5.0.1, Xcode's git has moved to inside So if you're using that:

source /Applications/
source /Applications/
export PS1='\u@\h:\w$(__git_ps1)$ '

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.