Search code examples
gitgit-configgit-alias

Error after adding an alias in global .gitconfig


I've added a line in my .gitconfig file on Windows:

[alias]
hist = log --pretty=format:"%C(yellow)%h [%ad]%C(reset) | %s%d %C(green)(%cr)%C(reset) by %C(blue)%an%C(reset)" --graph --all --decorate --date=short

This code works fine if I use it from the git command line (like git log --pretty=...). But when I use alias, I get this error:

$git hist
fatal: |: no such path in the working tree.
Use 'git <command> -- <path>...' to specify paths that do not exist locally.

As I understand, the problem is in the "|" symbol. It is interpreted by command line as a path. Should I isolate it somehow, or something else?


Solution

  • You need to escape your quotes:

    [alias]
    hist = log --pretty=format:\"%C(yellow)%h [%ad]%C(reset) | %s%d %C(green)(%cr)%C(reset) by %C(blue)%an%C(reset)\" --graph --all --decorate --date=short