Display a graph of all Git commits in a repository

To show a graph with all commits in a git repository in a tree structure, use the --all and --graph flags:1

git log --all --graph
* commit 8db8b3b2db9168bb724394ba3f34fd220352ebbc
| Author: Bob <bob@example.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     D
| 
* commit 01026bf42b9322f598d327e2a7b9ade7adfaf16c
| Author: Bob <bobexample.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     C
|   
| * commit f4e6c9253054184e7232984dc2c7b397e44064bb
| | Author: Alice <alice@example.com>
| | Date:   Mon Apr 17 15:15:51 2023 +0200
| | 
| |     F
| | 
| * commit cca2d230a40591fc6eb9acf6fd227c50f13c064d
|/  Author: Alice <alice@example.com>
|   Date:   Mon Apr 17 15:15:51 2023 +0200
|   
|       E
| 
* commit 091170c081ec541a4848d86861fea879829c15d9
| Author: Alice <alice@example.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     B
| 
* commit 5c38ea91a16724027398be23cd6d458929401b1d
  Author: Alice <alice@example.com>
  Date:   Mon Apr 17 15:15:51 2023 +0200
  
      A

Many of git log’s flags work as expected when displaying the log as a graph. To add the revision names, add --decorate:

git log --all --graph --decorate
* commit e7b47baa9c8ff178aee638a85f19545f3fced05b (HEAD -> main)
| Author: Alice <alice@example.com>
| Date:   Mon Apr 17 13:39:31 2023 +0200
| 
|     F
| 
* commit da1f36b79fd29005822b2b274f482a1a0ae3de21
| Author: Alice <alice@example.com>
| Date:   Mon Apr 17 13:39:30 2023 +0200
| 
|     E
|   
| * commit f3383d2d6bfecf3f419910f84d9d0cdf1ddb49e4 (feature)
| | Author: Bob <bob@example.com>
| | Date:   Mon Apr 17 13:39:30 2023 +0200
| | 
| |     D
| | 
| * commit 2c7c563705cc2f0f5b611114dde59ab25362e5e9
|/  Author: Bob <bobexample.com>
|   Date:   Mon Apr 17 13:39:30 2023 +0200
|   
|       C
| 
* commit 782a1a8496a10ccd2185679594d42e93232baca9
| Author: Alice <alice@example.com>
| Date:   Mon Apr 17 13:39:30 2023 +0200
| 
|     B
| 
* commit ffcdb6989336a5974704ceada90dbede8dd48581
  Author: Alice <alice@example.com>
  Date:   Mon Apr 17 13:39:30 2023 +0200
  
      A

To show a more compact tree by displaying each commit on a single line, use the --oneline flag:

git log --all --graph --decorate --oneline
* ebca060 (feature) D
* dc938b3 C
| * 273e73a (HEAD -> main) F
| * 725340c E
|/  
* 0348d04 B
* a4665f8 A

To abbreviate the commit hashes, use --abbrev-commit:

git log --all --graph --decorate --abbrev-commit --decorate
* commit 8db8b3b (feature)
| Author: Bob <bob@example.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     D
| 
* commit 01026bf
| Author: Bob <bobexample.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     C
|   
| * commit f4e6c92 (HEAD -> main)
| | Author: Alice <alice@example.com>
| | Date:   Mon Apr 17 15:15:51 2023 +0200
| | 
| |     F
| | 
| * commit cca2d23
|/  Author: Alice <alice@example.com>
|   Date:   Mon Apr 17 15:15:51 2023 +0200
|   
|       E
| 
* commit 091170c
| Author: Alice <alice@example.com>
| Date:   Mon Apr 17 15:15:51 2023 +0200
| 
|     B
| 
* commit 5c38ea9
  Author: Alice <alice@example.com>
  Date:   Mon Apr 17 15:15:51 2023 +0200
  
      A

  1. https://stackoverflow.com/a/1064431 ↩︎