Skip to content

Instantly share code, notes, and snippets.

@hungpk
Forked from trey/happy_git_on_osx.md
Last active May 9, 2017 04:05
Show Gist options
  • Save hungpk/19ecccf2c245d1456a95e0f6942b1ece to your computer and use it in GitHub Desktop.
Save hungpk/19ecccf2c245d1456a95e0f6942b1ece to your computer and use it in GitHub Desktop.
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion bash-git-prompt

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 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).

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
source /usr/local/Cellar/git/2.12.2/share/zsh/site-functions/git-completion.bash
if [ -f /usr/local/share/gitprompt.sh ]; then
    GIT_PROMPT_THEME=Default
    . /usr/local/share/gitprompt.sh
fi

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

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

Sources

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