Git Config

Here is my fancy Git setup to make things pretty and easy. First is the .gitconfig

	name = Steven Barre
	email =
	editor = vim
	tool = vimdiff
	ui = auto
        br = branch
        ci = commit
        co = checkout
        dc = diff --cached
        di = diff
        last = log -1 HEAD
        lr = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative --graph
        ls = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph
        la = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [Committed\\ by:\\ %cn]%Cgreen\\ [Authored\\ by:\\ %an]" --decorate --date=short --graph
        search = grep --break --heading --line-number -P
        st = status
        unstage = reset HEAD --
        default = current

This gives you a bunch of nice aliases, colorizes the output, and sets VIM as the default editor and merger.

The default push action lets you just say “git push” on a new branch and have it create a matching repo on the remote and set it as the upstream. git-config docs for reference.

Next we’ll add some goodies to .bashrc to give us a pretty prompt.

First, we need to get the extra git shell functions loaded. We do this by linking the contrib file into /etc/profile.d

# sudo ln -s /usr/share/git-core/contrib/completion/ /etc/profile.d/

Then put this into your .bashrc

# Show colors for branch name and indicators
# Show unstaged (*) and staged (+)
# Show if something is stashed ($)
# Show if there are untracked files (%)

# User@Host:pwd $
# User@host:pwd (branch) $
export PROMPT_COMMAND='__git_ps1 "\[\033[31;1m\]\u\[\033[0m\]@\[\033[34;1m\]\h\[\033[0m\]:\[\033[33m\]\w\[\033[0m\]" " \$ "'

Here is what it looks like.


Why .bashrc ? Because it’s loaded for all bash shells, not just ones created when logging in. This is important if you are using screen or a GUI terminal.

I’ve created a repo on GitHub to hold all my dotfiles to keep track of things like this.