DEV Community

Shahid
Shahid

Posted on

A Practical Guide to Gemini CLI

Advanced Usage Examples for Gemini CLI

Gemini CLI is a powerful AI assistant for developers, but its true potential shines when you leverage its advanced features and workflow integrations. Here are practical, effective usage examples to help you get more out of Gemini CLI:

1. Deep Codebase Exploration and Summarization

  • Summarize architecture and module roles:
  gemini -p "@./ Summarize the architecture and main modules of this project"
Enter fullscreen mode Exit fullscreen mode
  • Explain a specific function or file:
  gemini -p "@src/utils/helpers.js Explain the purpose and logic of this file"
Enter fullscreen mode Exit fullscreen mode
  • Map data flows or dependencies:
  gemini -p "@src/ @lib/ Map the data flow between these directories"
Enter fullscreen mode Exit fullscreen mode

2. Automated Bug Detection and Fixing

  • Analyze and fix a GitHub issue:
  gemini -p "@search https://github.com/yourrepo/issues/123 Analyze this issue and suggest a fix plan"
Enter fullscreen mode Exit fullscreen mode
  • Detect and fix bugs in a directory:
  gemini -p "@src/ Scan for common bugs and suggest fixes"
Enter fullscreen mode Exit fullscreen mode
  • Apply suggested code changes:
    • Gemini will preview diffs and ask for your approval before applying edits[1].

3. Test Generation and Coverage Analysis

  • Generate unit tests for a file:
  gemini -p "@src/components/Button.jsx Generate unit tests for this component"
Enter fullscreen mode Exit fullscreen mode
  • Review and improve test coverage:
  gemini -p "@src/ @tests/ Analyze and suggest improvements for test coverage"
Enter fullscreen mode Exit fullscreen mode
  • Create integration tests:
  gemini -p "@api/ Generate integration tests for all endpoints"
Enter fullscreen mode Exit fullscreen mode

4. Documentation and Reporting

  • Generate markdown documentation:
  gemini -p "@src/ Generate markdown documentation for all exported functions"
Enter fullscreen mode Exit fullscreen mode
  • Summarize recent changes as a changelog:
  gemini -p "Summarize all codebase changes today in changelog format"
Enter fullscreen mode Exit fullscreen mode
  • Save documentation to a file:
  gemini -p "Save this summary as docs/CHANGELOG.md"
Enter fullscreen mode Exit fullscreen mode

5. Workflow Automation and Integration

  • Automate code review in CI/CD:

    • Add to your pre-commit hook:
    #!/bin/bash
    gemini review --staged-files --format=checklist
    
  • Generate docs during build:

  gemini docs --input=src/ --output=docs/ --format=markdown
Enter fullscreen mode Exit fullscreen mode
  • Integrate with Makefile:
  review:
    gemini review --files="$(FILES)" --severity=medium
  docs:
    gemini docs --auto-update --watch
Enter fullscreen mode Exit fullscreen mode

6. Shell and System Commands

  • Run shell commands directly:
  !ls -al
  !npm test
Enter fullscreen mode Exit fullscreen mode
  • Search for text within files:
  gemini -p "Find all TODO comments in the codebase"
Enter fullscreen mode Exit fullscreen mode

7. Project Customization and Memory

  • Define project rules and context in GEMINI.md:
  # Project: E-commerce Platform
  ## Context
  - React frontend, Node.js backend, MongoDB
  ## Standards
  - Use functional components
  - Follow REST API conventions
Enter fullscreen mode Exit fullscreen mode
  • Store preferences for consistent AI responses:
  gemini -p "Remember: always use async/await in this project"
Enter fullscreen mode Exit fullscreen mode

8. Real-Time Web Search and Research

  • Ground prompts with live web data:
  gemini -p "@search What are the latest security best practices for Node.js?"
Enter fullscreen mode Exit fullscreen mode
  • Fetch and analyze external data:
  gemini -p "@web-fetch https://api.example.com/data Analyze this API response"
Enter fullscreen mode Exit fullscreen mode

9. Multi-Agent and MCP Integration

  • Extend Gemini CLI with custom tools via MCP:
    • Configure .gemini/settings.json to add new abilities (e.g., GitHub integration, image generation)[1][2].
  • Interact with external APIs or services:
  gemini -p "Use the GitHub MCP tool to list all open pull requests"
Enter fullscreen mode Exit fullscreen mode

10. Batch Jobs and Non-Interactive Mode

  • Automate repetitive tasks:
  gemini --all_files -p "Refactor all functions to use ES6 syntax"
Enter fullscreen mode Exit fullscreen mode
  • Run in CI/CD pipelines for automated analysis and reporting[3]:
  gemini review --all_files --format=summary
Enter fullscreen mode Exit fullscreen mode

Table: Gemini CLI Built-in Tools Overview

Tool Command Example Description
ReadFolder ls List files/folders in a directory
ReadFile read-file Read content of a single file
ReadManyFiles read-many-files Read multiple files at once
FindFiles glob Search files by pattern
SearchText grep Search for text within files
Edit edit Apply code changes via diffs
WriteFile write-file Create new files with content
Shell !npm test Run shell/system commands
WebFetch web-fetch Fetch and analyze web content
GoogleSearch web-search Perform Google search for real-time info
SaveMemory memoryTool Store facts/preferences for session

Tips for Effective Use

  • Use the @ syntax to reference files or directories for context-aware prompts.
  • Leverage the 1 million token context window for large projects.
  • Integrate Gemini CLI into your scripts, CI/CD, and editor workflows for automation and consistency.
  • Customize project behavior with GEMINI.md and settings files for tailored AI responses[1][2][4].

By combining these advanced examples and integrations, you can unlock the full power of Gemini CLI for code analysis, automation, documentation, and workflow optimization[1][2][4][3].

[1] https://www.datacamp.com/tutorial/gemini-cli
[2] https://dev.to/proflead/gemini-cli-full-tutorial-2ab5
[3] https://www.infoq.com/news/2025/07/google-gemini-cli/
[4] https://mpgone.com/how-to-use-gemini-cli-complete-guide-for-developers-and-beginners/
[5] https://github.com/google-gemini/gemini-cli
[6] https://github.com/reugn/gemini-cli
[7] https://buymeacoffee.com/rsahan/gemini-your-terminal-a-comprehensive-guide-using-gemini-cli
[8] https://astconsulting.in/gemini-cli/gemini-cli-future-ai-command-lines
[9] https://www.youtube.com/watch?v=T76NbeTdDFA
[10] https://dev.to/therealmrmumba/7-insane-gemini-cli-tips-that-will-make-you-a-superhuman-developer-2d7h
[11] https://www.youtube.com/watch?v=VSiHh4KyK6A
[12] https://learn.netdata.cloud/docs/ai-&-ml/devops-copilot/gemini-cli
[13] https://www.youtube.com/watch?v=lEBO36eovns
[14] https://www.youtube.com/watch?v=bMSq6ghdIYk
[15] https://cloud.google.com/gemini/docs/codeassist/gemini-cli
[16] https://www.youtube.com/watch?v=CqL5kB8pOfo
[17] https://blog.google/technology/developers/introducing-gemini-cli-open-source-ai-agent/
[18] https://www.reddit.com/r/GeminiAI/comments/1lkojt8/gemini_cli_a_comprehensive_guide_to_understanding/
[19] https://momen.app/blogs/practical-tips-for-using-gemini-cli-in-real-projects/
[20] https://www.youtube.com/watch?v=we2HwLyKYEg
[21] https://github.com/Ramesh-tester/gemini-cli-action
[22] https://www.linkedin.com/pulse/drowning-pull-requests-automate-your-github-workflow-franziska-2rexe
[23] https://cloud.google.com/code/docs/shell/write-code-gemini
[24] https://devops.com/gemini-cli-the-open-source-ai-agent-thats-revolutionizing-terminal-workflows/
[25] https://www.marktechpost.com/2025/06/28/getting-started-with-gemini-command-line-interface-cli/
[26] https://github.com/google-gemini/gemini-cli/actions/workflows/ci.yml
[27] https://www.linkedin.com/pulse/gemini-command-line-interface-cli-ultimate-ai-agent-lozano-grijalba-tkl2f

Top comments (0)