41

I frequently type git log when what I actually want is git log --decorate. How do I make it decorate by default?

I have seen lots of answers of the form "make an alias lg and then type git lg instead of git log". But, I can't find anywhere how to change the default behaviour of git log itself. alias log does not work.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Benubird
  • 17,201
  • 25
  • 87
  • 134
  • Git does not allow aliases to shadow existing commands, so you cannot create an alias called `log`. – Chris Feb 06 '14 at 16:11
  • Note: Git 2.1 now proposes `decorate=auto`. See [my answer below](http://stackoverflow.com/a/25097285/6309) – VonC Aug 02 '14 at 16:47
  • Note bis (3 years later): with the upcoming Git 2.13, `--decorate` becomes the default for `git log`: see [my revised answer below](http://stackoverflow.com/a/25097285/6309). – VonC Apr 16 '17 at 23:29

2 Answers2

62

git config log.decorate auto

For a global setting, add the --global parameter.

So it would be:

git config --global log.decorate auto

The aliases are made with git config alias.lg "log --decorate"

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Jakub
  • 1,027
  • 8
  • 21
23

Update April 2017, 3 years later:

With Git 2.13 (Q2 2017), no need for configuration: --decorate is the default!

See commit 940a911 (24 Mar 2017) by Alex Henrie (alexhenrie).
(Merged by Junio C Hamano -- gitster -- in commit d9758cf, 11 Apr 2017)

The default behaviour of "git log" in an interactive session has been changed to enable "--decorate".

That means you would need to override that option on command line, to get back to the old behavior (for just one log execution):

git -c log.decorate=false log

Original answer (mid 2014)

Note: since git 2.1.0-rc0 (July 2014), Linus Torvalds himself introduced a decorate=auto option.
That is more precise than just decorate=true, especially for scripting purpose, as explained below.

See commit 1571586 by Linus Torvalds (torvalds):

This works kind of like "--color=auto" - add decorations for interactive use, but do not change defaults when scripting or when piping the output to anything but a terminal.

You can use either

[log]
     decorate=auto

in the git config files, or the "--decorate=auto" command line option to choose this behavior.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755