Creating a Happy Git Environment on OS X Leopard
Configure things:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global alias.co checkout
git config --global apply.whitespace nowarn
Setup an SSH key
ssh-keygen
Hit return a couple of times — leave password blank if you want.
cat ~/.ssh/id_rsa.pub | pbcopy
Paste that code into your settings page on your repository host(s).
Set up Global Git Config on your GitHub account page (the same place you pasted your SSH key). You’ll type in some stuff that looks like this:
git config --global github.user [your_username]
git config --global github.token [your_token]
Get happy Git colors. Paste the following into your ~/.gitconfig file:
[color]
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:
.DS_Store
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
GIT_PS1_SHOWDIRTYSTATE=true
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/example.com (master*)]$
Bonus
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 user.email "you@example.com"
It’s the same command as before, this time just omitting the --global.
Comments
Thank you! This is exactly the information I have been looking for!
Hi.
Thanks! This information saved my day!!!
Thanks Trey – this is nice and compact! Just one thing I found with git version 1.6.6 (installed into /usr/local): I had to add the full / path for my global .gitexcludes file to .gitconfig, whereas 1.6.4 worked with a quoted string of the filename alone.
Man, you have no idea the troubles that just got solved via your last tip, about leaving out the –global on the email config. I’ve fought the good fight on trying to reconcile “I want gitorious (work address) to show my commits etc.. but I want github updates via my non work address etc….)”. It seems so obvious now :) I know other guys at work who gripe about this same thing and all we had to do was look at that flag! hahahahaahahah that is awesome thanks for posting this here! I have a file full of stuff that I use but I don’t really put anywhere for fear of someone thinking “oh wow you don’t know that” but I bet no matter what it is and how much of an expert you are there are always bash tricks, textmate shortcuts etc that you miss, and stuff like you have here is awesome. I’m going to clean mine out and put it on github to. Thanks Trey!!!
Chris,
Glad you got some use out of that tip. Yeah, I have given up trying to not look stupid online. :) I like to just throw things out there, and if people think I’m stupid for not knowing it already, c’est la vie.
What do you think about that?