Skip to content
jzalinger edited this page Jul 22, 2011 · 3 revisions

Git Tweaks

Required

You need to set your username and email so that anyone else using git knows who committed what.

$git config --global user.name "Robert C. Ball"
$git config --global user.email "rball@bowdoin.edu"

If you are working on someone else’s user name, or on a shared account, you will not want to set these globally. If you leave off the ‘—global’ option, you can sent these values for each individual git repository, thus enabling multiple people to maintain separate repositories on the same computer. We would like to maintain accountability for all code changes, less for blaming people when something goes wrong than for being able to find out who to talk to about a problem.

Optional

You will probably find it useful to set some aliases. Let’s be honest, we’re all lazy, and typing “checkout” over and over is annoying, so eventually you’ll want to set at least a few of these up.

$git config --global alias.br branch
$git config --global alias.ci commit
$git config --global alias.co checkout
$git config --global alias.st status

If you prefer not to use vi (the default editor) you can set your editor with the command:

$git config --global core.editor "emacs -nw"

(On linux, this sets the editor to be emacs on the command line. Remove the ‘-nw’ to pop up a GUI.)

You can colorize the output of many git commands too:

$git config --global color.status auto

Productivity Enhancements

To see your currently checked out git branch in your command prompt, add this to your .bashrc, .profile, .bash_profile, or equivalent:

#Git branch in the prompt
export PS1='\
[\033[01;32m\]\u@\h\
[\033[01;34m\] \w\
[\033[31m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\
[\033[01;34m\]$\
[\033[00m\] '

Since the github wiki, or possibly just your browser in general, does some weird auto formatting, the above code is written across a bunch of different lines. Sorry. Make sure that when you put this into your bash profile, you only have it on 2 lines: the first is “#Git branch in the prompt”, the second line should be everything else (without any line breaks).

On mac OS X, to be able to tab complete names of branches, remotes, etc in git, download this file and rename it (use the ‘mv’ command in the terminal) to ~/.git-completion.sh
Then, add this line to your .bash_rc, .profile, .bash_profile, or equivalent:

source .git-completion.sh

Other Links

Git Guide
Git Rules

Clone this wiki locally