In this categoryGemini ยท 24
- How to Install the Gemini CLI and Run Your First PromptStart
- How to Get a Gemini API Key from Google AI Studio
- How to Call the Gemini API from Python
- How to Give Gemini CLI Project Context with a GEMINI.md File
- How to Choose the Right Gemini Model for Coding Tasks
- How to Fix a Bug in Your Codebase with the Gemini CLI
- How to Set Up Gemini Code Assist in VS Code
- How to Stream Gemini Responses in Node.js
- How to Feed a Long Document into Gemini's Long Context
- How to Run the Gemini CLI Non-Interactively in Scripts
- How to Analyze a Video File with the Gemini API
- How to Connect an MCP Server to the Gemini CLI
- How to Fix Common Gemini CLI Authentication Errors
- How to Cache Long Context in the Gemini API to Cut Costs
- How to Summarize a YouTube Video with Gemini
- How to Analyze PDFs and Docs in the Gemini Chat App
- How to Extract Data from Images and Screenshots with Gemini
- How to Generate a Short Video with Veo in Gemini
- How to Ground Gemini Answers in Your Own Documents
- How to Use Gemini Inside Google Docs to Draft Faster
How to Fix a Bug in Your Codebase with the Gemini CLI
Use the Gemini CLI agent to locate, diagnose, and patch a real bug, then review the diff before accepting.
The Gemini CLI is an agent, not just a chat box. It can read files, run your tests, propose an edit, and apply it once you approve. This guide walks through using it to chase down a failing test and ship a fix you actually understand.
What you need
- The Gemini CLI installed and signed in
- A project with a reproducible bug or a failing test
- Git initialized so you can review and revert changes
- About 10 minutes
Step 1: Reproduce the failure first
Before involving the agent, run the failing test yourself so you have a clear signal. Knowing the exact error message lets you verify the fix later instead of trusting the agent blindly.
Step 2: Describe the bug to the agent
Launch gemini in the project folder and describe the symptom precisely, pasting the failing assertion. Ask it to investigate before changing anything, which keeps the first response focused on diagnosis.
Step 3: Review the proposed diff
When the agent proposes an edit, the CLI shows a colored diff and asks you to approve, reject, or modify. Read it carefully. Accept only if the change matches your understanding of the bug from step 1.
function getTotal(items) {
- return items.reduce((sum, i) => sum + i.priceCents, 0);
+ return items.reduce((sum, i) => sum + i.priceCents, 0) / 100;
}Step 4: Confirm the fix
After the edit is applied, ask the agent to run the tests, or run them yourself. Seeing the same test pass confirms the fix without you having to take the agent's word for it.
Result
The failing test now passes from a one-line change you read and understood. Because git tracked the edit, you can review git diff one more time and commit, or revert in a second if you change your mind.
Watch related tutorials
16:12
3:58:44
12:00
09:00
14:00
15:50New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.