More git tips and tricks
Here are a couple more fun git commands and configuration tricks.
Make some aliases because typing ‘checkout’ is a pain. In ~/.gitconfig:
Note the quicklog command below uses a custom log format which shows you a short hash, a relative date (”4 hours ago”) and the commit message. I created it by reading the git log formatting manpage.
[alias]
ci = commit
co = checkout
b = branch
nb = checkout -b
stat = status
sl = stash list
sa = stash apply
sd = stash drop
quicklog = log –pretty=format:\”%h %cr %cn %Cgreen%s%Creset\”
changes = log –pretty=oneline
svnup = svn rebase
svnpush = svn dcommit
I really love the ‘nb’ alias, which I use to mean ‘new branch’. It lets me very quickly create and switch to a new branch “git nb fixing_bug_123″.
Display the current branch in your bash prompt. Modified from here.
export MANPATH=/usr/local/git/man:$MANPATH
function parse_git_branch {
git branch 2> /dev/null | \
sed -e '/^[^*]/d’ -e ’s/* \(.*\)/(\1) /’
}
export PS1=’\u@\H:\w $(parse_git_branch)$ ‘
Get a nice list of change summaries, one line per change
git log --pretty=oneline --since="2 weeks ago" --until="yesterday"
See what changed from one commit set to another (these can be branch names)
git log my-branch..master
See which files changed in the log
git log --name-status
Browse your local repo with a web interface
git instaweb --httpd=webrick
Want to reorder previous commits, squash commits, and generally wreak havoc?
The following command opens up an interactive editor with the last 10 commits.
git rebase -i HEAD~10










No Comments Yet