Skip to content

Instantly share code, notes, and snippets.

@dstandish
Forked from trey/happy_git_on_osx.md
Last active July 24, 2018 18:14
Show Gist options
  • Save dstandish/c4d0b56488c05340348c4dbd562810e3 to your computer and use it in GitHub Desktop.
Save dstandish/c4d0b56488c05340348c4dbd562810e3 to your computer and use it in GitHub Desktop.
Creating a Happy Git Environment on macOS

Creating a Happy Git Environment on macOS

Install git and bash-completion on your machine

Install Git

brew install git bash-completion

Basic config:

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

Configure SSH authentication

Create an SSH key

ssh-keygen

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

Copy your ssh key into memory:

cat ~/.ssh/id_rsa.pub | pbcopy

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

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

Bash profile additions

Git aliases

alias g="git"
alias ga="git add"
alias gc="git checkout"
alias gcm="git commit -m"
alias gm="git merge"
alias gp="git pull"
alias gll="git ll"
alias gl="git log"
alias gs="git status"

bash history

# bash history
shopt -s histappend
export HISTCONTROL=ignoredups:erasedups
HISTFILESIZE=100000
HISTSIZE=10000
PROMPT_COMMAND=$PROMPT_COMMAND'history -a; '

virtualenvwrapper:

# virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh
CYAN=$(tput setaf 6)
NORMAL=$(tput sgr0)
function __venv_prefix {
	if test "$VIRTUAL_ENV" ; then
		printf "(${CYAN}`basename \"$VIRTUAL_ENV\"`${NORMAL}) "
	fi	
}
PROMPT_COMMAND=$PROMPT_COMMAND'__venv_prefix; '

Git bash completion

# git bash completion
[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWCOLORHINTS=true
PROMPT_COMMAND=$PROMPT_COMMAND'__git_ps1 "\w" ":\$ "; '
__git_complete g __git_main
__git_complete gc _git_checkout
__git_complete gm __git_merge
__git_complete gp _git_pull

syntax highlighting in vim

Add syntax on to ~/.vimrc

Repo-specific emails

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.

Sources

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