One of the things I can’t live without is git bash integration in my $PS1. This gives me feedback on the branch and status of my current directory. Here’s an example screenshot:
So how do you get this set up? Here’s how I do it (in ~/.bash_profile):
GIT_COMPLETION_PATH=/etc/bash_completion.d/git if [ -f $GIT_COMPLETION_PATH ]; then . $GIT_COMPLETION_PATH GIT_PS1_SHOWDIRTYSTATE=true # */+ for dirty GIT_PS1_SHOWSTASHSTATE=true # $ for stashes GIT_PS1_SHOWUNTRACKEDFILES=true # % for untracked fi
And then you can just include the git completion function in your $PS1 where you want it. My $PS1 is super simple, and just has this and the current path (and some nice colors):
export PS1="\e[0;33m\w\e[0;91m\$(__git_ps1 ' (%s)')\e[0;96m \$\e[0m "
Note: the location of your git bash_completion directory may be different (especially if you installed git via homebrew). I like to solve that with a symbolic link, instead of changing this configuration (I just find it cleaner that way – much nicer for upgrades too):
git -> /usr/local/Cellar/git/1.7.9.6/etc/bash_completion.d/git-completion.bash
If you like this – read more of my dotfiles
I use `git stash` very often to set some code aside while I work temporarily in another branch. Sometimes, I want to peek at what I have stashed instead of taking it out. You can do that very easily with `git stash show`:
git stash show -p # view a diff
Another vim plugin I love enough to feature here is git-vim which gives you convenient access to git commands from inside of vim. I only use a few of them (and only in their base form) – but I find them pretty indispensable:
:GitLog
Will open a git log in a new buffer of the changes to the current file
:GitBlame
Will open a vertical buffer containing the line-by-line blame of the current file
:GitDiff
Will open a buffer next to the existing buffer, with its current diff
Today I’m going to talk about a way to search git history. Imagine you want to find out when a certain term was changed (as part of an add or remove) in your project. The git log “pickaxe” operator is just for that.
$ git log -S "some_string_you_know"
will show you the git log history of only commits that contain the given string in an add or remove.
It’s super useful for dealing with code you’ve never seen before, or searching for the last change to a term that you know exists.
I can’t live without colors in Git, but I see a lot of people using Git without them on. They make it really nice to view diffs in a console — as well as beautifying status and branch lists.
To enable them (with the defaults) just run:
$ git config --global color.ui true