Viewing Git Graph in ASCII

CK CK 3788 
Created at
Updated at  
600 0 0

You can absolutely view a Git commit graph in ASCII art directly within your terminal for recent commits. This is a powerful feature of git log that helps visualize branching, merging, and commit history.

 

Basic Command Explanation

The core command to generate an ASCII graph uses the --graph option with git log. To make it more concise and readable, it's often combined with other options:

git log --graph --oneline --decorate --all
  • --graph: Instructs Git to draw the commit graph in ASCII.
  • --oneline: Condenses each commit entry to a single line, showing the shortened SHA-1 hash and the commit subject. This significantly improves readability for the graph.
  • --decorate: Shows branch and tag names pointing to specific commits. This is crucial for understanding where your HEAD, branches, and tags are located in the graph.
  • --all: By default, git log only shows the history of the current branch. --all includes commits from all local and remote-tracking branches, providing a complete picture of your repository's history.

 

Its result will be like below:

Viewing Git Graph in ASCII

 

Limiting Commits

To focus on "recent commits," you can use various options with git log:

  • By number:
git log --graph --oneline -n 10 # Shows the last 10 commits
  • By date:
git log --graph --oneline --since="2 weeks ago" # Commits within the last two weeks
git log --graph --oneline --after="2023-01-01" # Commits after a specific date
  • By commit range:
git log --graph --oneline HEAD~5..HEAD # Shows the last 5 commits from HEAD

This shows commits reachable from HEAD but not from HEAD~5.

 

Customizing Output Format

For even more control over what information is displayed alongside the graph, you can use the --pretty=format: option. This allows you to define a custom format string using placeholders.

 

Common placeholders:

  • %h: Abbreviated commit hash
  • %H: Full commit hash
  • %d: Ref names (branches, tags)
  • %s: Subject
  • %cr: Relative commit date (e.g., "2 weeks ago")
  • %an: Author name
  • %C(...): Color options

Example for a detailed custom format with color:

git log --graph --pretty=format:'%C(yellow)%h%Creset -%C(auto)%d%Creset %s %C(green)(%cr) %C(blue)<%an>%Creset' --all

 

This format would output:

  • Yellow commit hash
  • Auto-colored ref names (branches/tags)
  • Subject
  • Green relative commit date
  • Blue author name

 

 

Creating Git Aliases

Typing these long commands repeatedly can be cumbersome. Git aliases allow you to create shortcuts in your ~/.gitconfig file.

Open or create ~/.gitconfig and add an [alias] section:

[alias]
    lg = log --graph --oneline --decorate --all
    lga = log --graph --pretty=format:'%C(yellow)%h%Creset -%C(auto)%d%Creset %s %C(green)(%cr) %C(blue)<%an>%Creset' --all
    lg10 = log --graph --oneline -n 10 --decorate

After saving, you can then simply type:

  • git lg to see the full graph.
  • git lga for the detailed, colored graph.
  • git lg10 for the last 10 commits with the basic graph.

 

Putting It All Together (Examples)

Here are some common and useful combinations:

1. Standard concise graph for all branches:

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

(Alias: git lg)

 

2. Last 15 commits on the current branch (with decorations):

git log --graph --oneline --decorate -n 15

 

3. Detailed, colored graph for all branches (alias lga):

git log --graph --pretty=format:'%C(auto)%h%Creset %C(bold yellow)%d%Creset %s %C(green)(%cr) %C(bold blue)<%an>%Creset' --all

 

4. Graph showing only commits since a specific date on all branches:

git log --graph --oneline --decorate --all --since="2023-10-01"

 

5. Graph showing only your own commits:

git log --graph --oneline --decorate --all --author="Your Name"

 

Using these options and aliases, you can tailor your terminal's Git graph view to precisely what you need to see, making it an invaluable tool for understanding your repository's history.

Tags git git graph Facebook X
Comments 0
Similar posts
  1. Simplify Your Workflow: Switching Git Profiles Automatically by Folder
    759
  1. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  2. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  3. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  4. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    175
  5. Messaging Platform with Limited TPS based on the vendor
    202
  6. Redis vs Memcached: Why Enterprise Tech Giants Choose Redis
    260
  7. ETL vs ELT what makes the differeence? Why MLOps leverage ELT?
    201
  8. Arm Kernel DNNs: Powering Efficient AI at the Edge
    229
  9. Cloud-Native Capital Markets: Architecture, Compliance, and Innovation
    218
  10. Add New Address to gmail without SMTP (forwarding-only-address)
    1,698
  11. Registering an App on the Google Play Store
    1,480
  12. AGENT.md: AI's Blueprint for Robust Software and Vibe Coding
    562
  13. Tailscale: Zero-Config Remote Access to Your Home PC, Firewall-Free
    538
  14. Markdown's Visual Revolution: Meet Mermaid.js
    417
  15. Vibe Coding: Harmonizing Intent with AI Productivity
    505
  16. How do I change the theme for code block in Confluence Cloud?
    1,395
  17. FIPS - Federal Information Processing Standards
    1,402
  18. How to Control External Monitor Brightness, Sound Volume on a Mac with MonitorControl (Even Over HDMI)
    2,407
  19. Building Multilingual Applications with i18n
    1,207
  20. Kiro versus Cursor AI - Spec-Driven? or Chat-Driven?
    407
  21. How to use multiple RSA (SSH) keys for GitHub
    337
  22. Key Metrics Track to Ensure the Health and Performance of a Distributed System
    180
  23. REST API Vs. GraphQL
    413
  24. Project Libre similar to MS Project
    532
  25. Learning about Firestore: Architecture, Pros, Cons, and Real-World Deployments
    172
  26. Building Privacy-First Infrastructure: Network Isolation + Zero Trust for GDPR Compliance
    298
  27. Why supabase is not safe for the Fintech project?
    861
  28. The Ultimate Data Engineering Roadmap
    1,082
  29. Nine Types of Testing while we develop APIs
    519
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    28
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  4. How do I create animated background for Google Meet?
    22,829
  5. Array of arguments passed to script in PHP
    97
  6. Invalid Auction Storms in Ad Tech
    106
  7. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  8. The Two Clocks of Ad Server Architecture
    77
  9. Frequency Cap Architecture Overview
    526
  10. Collecting Proof-of-Play from 100,000 Screens
    152
  11. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  12. What is RedisVL?
    114
  13. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  14. TPU & GPU Cluster Management Tools
    257
  15. The Concept of Scaffolding in AI Agents
    244
  16. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  17. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  18. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  19. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  20. Machine Learning: Training vs. Ranking
    229
  21. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  22. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  23. Designing a Data Curation System Around a Vector Database
    230
  24. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  25. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  26. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  27. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  28. Understanding Data Lineage
    271
  29. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    255
  30. Java Variant Type
    210