One of the most used git command is git log
which shows commit logs.
$ git log
I found custom git lg
looks more self-sufficient and descriptive. If you want to have this command follow next instruction.
Following image shows what's the difference between custom git lg
and git log --oneline
.
Instruction:
Go to C:\Users\YOURUSERNAME
and add code in .gitconfig file:
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches
That's it!
From now on you can call git lg
and have new view in terminal. Enjoy!
Top comments (20)
Cool tip.
I am on Linux, and I use the OhMyZsh shell that have already pretty print alias for
git log
, and for example theglg
one looks like:I don't work on Linux but anyway it always good to know other solutions
The alias I have in Linux should work in Windows to, just give it a try... define them in the same way you have define the one in this article.
Or just use Git Fork
I personally prefer CLI for things like git. I've had too many bad experiences in the past with gui tools. I feel safer knowing exactly what commands I'm issuing
Agree with you. I had such cases too, for ex. Sourcetree sometimes didn't want to launch at all. It sucks.
Sourcetree is terrible don't use that. If you’re on Windows or Mac give Git Fork a try. I used Sourcetree before I loved how it looked and how simple it was but it was slow and buggy it actually made me switch to command line. I just don’t like typing out the commands all the time.
100% true about Sourcetree.
I love Sourcetree. It got better. For cherry picking very handy.
Use cherry-picking with interactive flag.
There's a button on Git Fork that shows you what commands it's calling underneath.
One of the reasons people prefer CLI over GUIs is the lack of difference between them. A cli is the same wherever, GUIs vary widely from usability to launching. Some have good features some have bad.
Also useful to know if you have to go on site and they don't have a GUI.
Skip to do what you want with CLI with a bit of practice. Git isn't too bad to learn on the CLI anyway.
I know CLI and I use it when the GUI doesn’t work. I just find typing the commands every time very tedious. I’d rather click to do what I want.
Never heard of it before. Tried all the others like tower, kraken etc. and settled on sourcetree. Haven't had issues, but I will give fork a try.
I swear every time I open DEV there's an article on the homepage that's relevant to what I'm looking for in the moment.
Super nice alias, thanks!
Good to know that you found what you was looking for. Welcome!
Nice, thanks. I did have a glg alias for this same log but I lost it in a recent resetup after my cygwin setup died on me.
Now I'm switching to WSL.
I spent a good amount of last night/early this morning trying to get a log view I was happy with. The best I could get was git log --graph --pretty --oneline but it lacks the author, date (relative) and tags. Yours looks like it has all but tags, but I think I saw that option last night while tab-exploring options ..
But would you mind explaining the black magic that is the pretty formatting syntax? I understand some of it...
Thanks for sharing <3
If you're into colorful tools (and who's not, right?), I recommend having a look at tig. 🚀
Will have a look!