Rarely handy Git commands

Compare two branches/tags #

This command will compare two branches/commits/tags/hashes (anything really) and will output a one-line-per-commit-nicely-formatted log

$ git log --decorate --date=relative --format=format:"%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)[%an]%C(reset)%C(bold yellow)%d%C(reset)" origin/master..HEAD

Thanks to the origin/master..HEAD at the end, this will show any commits on your local branch which are not on your remote. Change this to whatever suits you - make sure there are two dots between the two.

See a diff without whitespace #

I have my editor to trim trailing spaces - if I open an old file and press save, it removes a space from (pretty much) every line. This can be messy when viewing a git diff. With the following command, you can git diff while ignoring whitespace

$ git diff --ignore-space-at-eol -b -w --ignore-blank-lines

Git log with a graph #

There may be times you wish to show a git log with a pretty graph on the command line, to work out where branches have split and merged

$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''%C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

Show today's commits #

You may wish to see what commits you have done today (especially handy if you work in a team)

$ git log --since=1am --author='Mike Street' --format='- %s'

Don't forget to change the author to your name

Delete all git tags #

To delete all the git tags:


$ git tag | xargs git tag -d


$ git tag -l | xargs -n 1 git push --delete origin