setia_'s answer remains the most appropriate but your question is meaningful because a git history can be considered from two distinct perspectives: either you totally view it as a (mathematical) graph in which parent's order is supposed to be non significant, OR you consider a merge operation as the integration of an external branch into a common trunk (i.e. your current branch, very often "master"). This is also the assumption made by git merge.

This is important not only because browsing an exponentially growing tree rapidly becomes a pain, but also because having a branch "master" that contains a finished product and integrating external submissions is a model followed by many workflows.

Since both these points of view are valid, they cause --first-parent to be a frequently used option, though not a main command nor a default behavior.

For example, browsing the Linux kernel main repository (for which Git was first designed) with a simple git log --graph can take up to one minute before displaying something, but git log --graph --first-parent will show you the main branch and let you observe that it's mainly composed of merges, with occasional direct commits.

Another thing one have to keep it mind is that you can ask to have your commits displayed by chronological order using --date-order or topological order with --topo-order. Let's assume you have two distinct branches and alternatively commit to the one or the other before eventually merging them. Depending on the order, the resulting graph would look like one of these :

Chronological order                     Topological order

*   ec9a124 Merge branch 'B' into A     *   ec9a124 Merge branch 'B' into A
|\                                      |\
* | e5314f2 Ninth                       | * e3e2435 Eighth
| * e3e2435 Eighth                      | * af3bac5 Sixth
* | 308228b Seventh                     | * 3a2f0b9 Fourth
| * af3bac5 Sixth                       | * d901c9f Second
* | ab11578 Fifth                       * | e5314f2 Ninth
| * 3a2f0b9 Fourth                      * | 308228b Seventh
* | 344bd0f Third                       * | ab11578 Fifth
| * d901c9f Second                      * | 344bd0f Third
|/                                      |/
* 0f029bc First                         * 0f029bc First

All commits remain on their respective line but the latter is a depth-first search. And since git log (so does git rev-list) displays a collection of pre-gathered revisions, this order will be the same whether you're using --graph or displaying them as a flat list (actually, if not specified, git log use reverse chronological order by default, and topological one when using --graph).

Because of that, you can't simply rely on the first row to decide which parent to choose.

This can also cause some older commits to appear before the new ones, which can be very confusing when beginning with Git, and give you the impression that your work has disappeared (until it comes to one's mind to perform a search, then retrieve it buried somewhere in history).

Answer from Obsidian on Stack Overflow
Top answer
1 of 2
6

setia_'s answer remains the most appropriate but your question is meaningful because a git history can be considered from two distinct perspectives: either you totally view it as a (mathematical) graph in which parent's order is supposed to be non significant, OR you consider a merge operation as the integration of an external branch into a common trunk (i.e. your current branch, very often "master"). This is also the assumption made by git merge.

This is important not only because browsing an exponentially growing tree rapidly becomes a pain, but also because having a branch "master" that contains a finished product and integrating external submissions is a model followed by many workflows.

Since both these points of view are valid, they cause --first-parent to be a frequently used option, though not a main command nor a default behavior.

For example, browsing the Linux kernel main repository (for which Git was first designed) with a simple git log --graph can take up to one minute before displaying something, but git log --graph --first-parent will show you the main branch and let you observe that it's mainly composed of merges, with occasional direct commits.

Another thing one have to keep it mind is that you can ask to have your commits displayed by chronological order using --date-order or topological order with --topo-order. Let's assume you have two distinct branches and alternatively commit to the one or the other before eventually merging them. Depending on the order, the resulting graph would look like one of these :

Chronological order                     Topological order

*   ec9a124 Merge branch 'B' into A     *   ec9a124 Merge branch 'B' into A
|\                                      |\
* | e5314f2 Ninth                       | * e3e2435 Eighth
| * e3e2435 Eighth                      | * af3bac5 Sixth
* | 308228b Seventh                     | * 3a2f0b9 Fourth
| * af3bac5 Sixth                       | * d901c9f Second
* | ab11578 Fifth                       * | e5314f2 Ninth
| * 3a2f0b9 Fourth                      * | 308228b Seventh
* | 344bd0f Third                       * | ab11578 Fifth
| * d901c9f Second                      * | 344bd0f Third
|/                                      |/
* 0f029bc First                         * 0f029bc First

All commits remain on their respective line but the latter is a depth-first search. And since git log (so does git rev-list) displays a collection of pre-gathered revisions, this order will be the same whether you're using --graph or displaying them as a flat list (actually, if not specified, git log use reverse chronological order by default, and topological one when using --graph).

Because of that, you can't simply rely on the first row to decide which parent to choose.

This can also cause some older commits to appear before the new ones, which can be very confusing when beginning with Git, and give you the impression that your work has disappeared (until it comes to one's mind to perform a search, then retrieve it buried somewhere in history).

2 of 2
2

Commit can have more than one parent. ^ 1 means first parent. ^2 means second parent and so on. Just ^ defaults to ^1 which is first parent.

Similarly ~ give access to traverse up for an ancestor. For example if you want 3 generation up ~3. If you want 7th last commit in same branch favouring first parent while traversing.

Any merge will have two parents with merge to branch becoming first parent. Merge from branch becoming second parent.

🌐
Git
git-scm.com › docs › git-log
Git - git-log Documentation
Cannot be combined with --graph. ... Overrides a previous --no-walk. ... Pretty-print the contents of the commit logs in a given format, where <format> can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>. When <format> is none of the ...
Top answer
1 of 16
2435

Update: I've posted an improved version of this answer to the Visualizing branch topology in Git question, since it's far more appropriate there. Leaving this answer for historical (& rep, I'll admit) reasons, though I'm really tempted to just delete it.

My two cents: I have two aliases I normally throw in my ~/.gitconfig file:

[alias]
lg1 = log --graph --abbrev-commit --decorate --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(auto)%d%C(reset)' --all
lg2 = 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(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
lg = lg1

git lg/git lg1 looks like this:

and git lg2 looks like this:


(Note: There now exists much more applicable answers to this question, such as fracz's, Jubobs', or Harry Lee's!)

2 of 16
2189

Many of the answers here are great, but for those that just want a simple one-line-to-the-point answer without having to set up aliases or anything extra, here it is:

git log --all --decorate --oneline --graph

Not everyone would be doing a git log all the time, but when you need it just remember:

"A Dog" = git log --all --decorate --oneline --graph

If you enter

git config --global alias.adog "log --all --decorate --oneline --graph"

at the command prompt once, you can use

git adog

from that prompt even if you close and reopen it.

🌐
GitHub
gist.github.com › niun › ca61a37791ff1fdc9b33
git log graph --oneline with date and author and colored ref names as alias · GitHub
git log graph --oneline with date and author and colored ref names as alias - set-pretty-git-log-alias.sh
🌐
Medium
medium.com › @ruqaiya.beguwala › day-22-30-git-log-graph-oneline-all-visualize-branch-history-81999ad9327e
Day 22/30 — git log — graph — oneline — all — Visualize branch history. | by Ruqaiya Beguwala | Medium
June 12, 2025 - Git provides powerful tools to inspect repository history, but the default git log output can be overwhelming. That’s where git log --graph --oneline --all comes in—it condenses commit history into an easy-to-read graph, showing branch relationships at a glance.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-git-stash-untracked-files
git log oneline examples
The oneline switch is the default ... switch, as there’s a built in alias for the command: ... A nice addition to the oneline switch is the –graph option....
🌐
Scaler
scaler.com › home › topics › git › git log --oneline
Git log --oneline - Scaler Topics
May 4, 2023 - ... The only issue with using the ... to fix that we can use this --graph option along with the --pretty oneline option in the git log command, in which the output will be in a much better format....
Find elsewhere
🌐
Atlassian
atlassian.com › git › tutorials › git-log
Advanced Git Log | Atlassian Git Tutorial
January 12, 2026 - The --graph option draws an ASCII graph representing the branch structure of the commit history. This is commonly used in conjunction with the --oneline and --decorate commands to make it easier to see which commit belongs to which branch:
🌐
Prsantos
prsantos.com › posts › 2021-03-07-git-log-graph
Peter R. Santos - Git log graph
March 7, 2021 - I don't want to type in git log with all the options to get the log graph, so I can just create the following alias in the terminal this way: $ git config --global alias.lg1 'log --all --decorate --oneline --graph'
🌐
giovanism
giovanis.me › post › git-log-all-graph-oneline
git log --all --graph --oneline | giovanism
February 8, 2022 - The --graph flag tells git to show commits as graph, connecting commits with their parrents. And lastly, the --oneline flag will tells git to show commit logs in oneline pretty format.
🌐
grep Flags
zwischenzugs.com › 2016 › 06 › 04 › power-git-log-graphing
Power 'git log' graphing - zwischenzugs.com
June 4, 2016 - git log --graph --oneline --all --decorate --simplify-by-decoration --pretty='%ar %s %h'
🌐
Think-like-a-git
think-like-a-git.net › sections › graphs-and-git › visualizing-your-git-repository.html
Visualizing Your Git Repository // Think Like (a) Git
You can also add --color to pretty up the display a bit more (sorry, no time to take a screenshot as I add this): git log --oneline --abbrev-commit --all --graph --decorate --color
🌐
freeCodeCamp
freecodecamp.org › news › git-log-command
Git Log Command Explained
January 11, 2020 - The --graph flag enables you to view your git log as a graph. To make things things interesting, you can combine this command with --oneline option you learned from above.
🌐
GitHub
gist.github.com › datagrok › 4221767
How to simplify the graph produced by git log --graph · GitHub
$ git log --graph --topo-order --decorate --oneline --all * f19e46d (dev) Merge branch 'master' into dev |\ | * 600a33f (HEAD, master) commit * | c9ccbf1 Merge branch 'master' into dev |\| | * 4c1fb52 commit * | dfdcb8a Merge branch 'master' into dev |\| | * 42b1c24 commit * | 7714be3 Merge branch 'master' into dev |\| | * f7eae2d commit |/ * 885700a initial empty commit
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Viewing-the-Commit-History
2.3 Git Basics - Viewing the Commit History
The oneline and format option values are particularly useful with another log option called --graph.
🌐
DEV Community
dev.to › ruqaiya_beguwala › day-2230-git-log-graph-oneline-all-visualize-branch-history-3pnc
Day 22/30 - git log --graph --oneline --all – Visualize branch history. - DEV Community
June 12, 2025 - Git provides powerful tools to inspect repository history, but the default git log output can be overwhelming. That’s where git log --graph --oneline --all comes in—it condenses commit history into an easy-to-read graph, showing branch relationships at a glance.
🌐
Explain Shell
explainshell.com › explain
explainshell.com - git log --oneline --graph --decorate --all
explainshell.com · about · theme · Light · git log(1) --oneline --graph --decorate --all · source manpages: git-log
🌐
Hacker News
news.ycombinator.com › item
Another quick visualization method built into Git: git log —-graph —-oneline —-d... | Hacker News
September 26, 2020 - git log —-graph —-oneline —-decorate # —-graph for the visualization # —-oneline for compact commits # —-decorate for tag and branch refs You can also add: · git log --graph --oneline --decorate
🌐
ttias.be
ma.ttias.be › pretty-git-log-in-one-line
Pretty git log in one line
August 25, 2015 - $ git log --pretty=oneline 3396763626316124388f76be662bd941df591118 Add twitter link c73bbc98b5f55e5a4dbfee8e0297e4e1652a0687 add facebook link · It’s taking up less space, but missing crucial information like the date of the commit. There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output. $ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit * 3396763 - (HEAD, origin/master, master) Add twitter link (4 days ago) <Mattias Geniar> * c73bbc9 - add facebook link (6 days ago) <Mattias Geniar> * cb555df - More random values (6 days ago) <Mattias Geniar> * 60e7bbf - Merge pull request #1 from TSchuermans/patch-1 (7 days ago) <Mattias Geniar> |\ | * 8044a8f - Typo fix (7 days ago) <Tom Schuermans> |/