Skip to content

Instantly share code, notes, and snippets.

@niksteff
Forked from trey/happy_git_on_osx.md
Last active August 29, 2015 13:56
Show Gist options
  • Save niksteff/8931388 to your computer and use it in GitHub Desktop.
Save niksteff/8931388 to your computer and use it in GitHub Desktop.

Creating a Happy Git Environment on OS X (or other unix like systems).

(soon for windows, too.)

Step 1: Install Git

Configure things:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global alias.co checkout
git config --global apply.whitespace nowarn

Setup an RSA SSH key

ssh-keygen -t rsa 

The prompt will ask you for a name. Keep it default if you are not that experienced with git. -- leave password blank if you want to. Otherwise you have to enter it with every push if you don't configer it otherwise.

cat ~/.ssh/id_rsa.pub | pbcopy

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

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:

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

On Mavericks 10.9 GIT has moved into XCodes App folder. (Thanks to mastbaum) So use this code instead:

source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\u@\h:\w$(__git_ps1)$ '

Also if you did install git with the help of homebrew you have to change the path above to something like this (have a look at your homebrew folder nonetheless to be sure):

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

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 in your terminal:

[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 "[email protected]"

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

Sources

@niksteff
Copy link
Author

I will update this with some new information and tipps from time to time. This is used for my work at Furtwangen University as well as in my position as a student at Furtwangen University and in some group projects as a knowledge base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment