Lullabot Ideas
We know stuff. We empower you to know stuff too.
Git Best Practices: History Viewing Tips and Displaying Branch Context
Article by Jerad BitnerMarch 31, 2011 - 9:00am
What's happenin'?
$ git log [<path>]commit 86ea8974821d6adaa198901b0fd5a3c046ade59c
Author: Jerad Bitner <obscured>
Date: Wed Mar 23 19:37:20 2011 -0600
adding the '/user' path with the same form id and using the paths as the selectors in the jquery
commit 7e965dd170d812324bc65833f67cc33d3dddc375
Author: Jerad Bitner <obscured>
Date: Wed Mar 23 16:52:09 2011 -0600
reload the window after a form submission$ git log --oneline [<path>]86ea897 adding the '/user' path with the same form id and using the paths as the selectors in the jquery
7e965dd reload the window after a form submission
927f2b6 adding an administrative page to customize width/height per form - also an alter hook to add other forms to the list (maybe I should call this modalframe_forms?)
c5979f2 initial commit of modalframe_login$ cd ~/git.drupal.org/modalframe_login
$ gitx
If you click on the 'Tree View' button at the bottom, you can get a list of all of the files and directories within your repository, and by right clicking on any file or directory, can then view the full history of just that file or directory.
So if you need to check what's going on with just one file or directory, Gitx is great. There are many other awesome GUI's out there now for Git, but I tend to stick to the basics.
What branch am I on?
Another great tool for visualizing where I am is a simple script in my ~/.bash_profile that parses the current directory for a .git directory and if found, will print out the name of the branch in my shell's command prompt.##############
## Bash prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local WHITE="\[\033[1;37m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="${TITLEBAR}\
$BLUE[$RED\$(date +%H:%M)$BLUE]\
$BLUE[$RED\u@\h:\w$GREEN\$(parse_git_branch)$BLUE]\
$GREEN\$ "
PS2='> '
PS4='+ '
}
proml[08:19][sirkitree@sirkitbox:~/git.drupal.org/modalframe_login]$ [08:20][sirkitree@sirkitbox:~/git.drupal.org/modalframe_login(master)]$ [08:21][sirkitree@sirkitbox:~/git.drupal.org/modalframe_login(master)]$ git checkout 6.x-1.x
[08:21][sirkitree@sirkitbox:~/git.drupal.org/modalframe_login(6.x-1.x)]$ 
Comments
Branch indicator
Hi,
for the branch indicator you can use the __git_ps1 script if it is available on your installation:
http://lostechies.com/jasonmeridth/2010/05/23/seeing-which-git-branch-i-...
It exposes more features like rebase status indication and some other stuff.
Ciao,
Antonio
VIM statusline
You can use a similar trick to set your VIM status line to reflect the current branch and other information about your working copy. I find it indispensable.
ZSH repo info
If you want to get even more fancy, check out the vcs_info plugin for the ZSH shell. It allows you to do all kinds of fun stuff like show branch, repo state, and current revision number. Also has seamless integration with all major version control systems (git, mercurial, bzr, svn, cvs, etc).
Here's an example of vcs_info in use:
http://www.eseth.org/2010/git-in-zsh/
Granted, it requires you to switch your shells, but zsh is a better shell then bash anyway :).
Cheers,
Jon
Another status line
I'm a big fan of this bash prompt, which shows the current SHA1 and some status flags too:
http://jeetworks.org/node/10
Simpler branch indicator what
Simpler branch indicator what leaves OSX default shell format intact:
<?phpfunction parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\h:\W \u\$(parse_git_branch)\$ "
?>
just got into branching
this was very helpful thanx