Beginner

Basic Commands

Learn the essential commands for working with Gemini CLI. From asking questions to editing files and running shell commands, this lesson covers everything you need to get productive.

Starting Gemini CLI

Launch Gemini CLI in your project directory to give it context about your codebase:

Terminal
# Basic start - interactive mode
$ gemini

# Start with a specific prompt
$ gemini "Explain the architecture of this project"

# Start with a specific model
$ gemini --model gemini-2.5-flash

# Pipe input from another command
$ cat error.log | gemini "Analyze these errors"

Asking Questions About Code

The simplest use case is asking Gemini CLI questions about your codebase:

Gemini CLI Session
# Understanding your project
> What does this project do?
> Explain the folder structure
> What frameworks and libraries does this project use?

# Finding specific code
> Where is the user authentication logic?
> Find all API endpoints in this project
> Show me where environment variables are used

# Understanding code
> Explain how the database connection pool works
> What does the middleware chain look like?
> Trace the request flow for POST /api/users

File Editing

Gemini CLI can directly edit files in your project. It shows you the proposed changes and asks for approval before applying them:

File Editing Examples
# Simple edits
> Add error handling to the fetchUser function in
  src/services/user.ts

# Creating new files
> Create a new utility file for date formatting
  with functions for relative time, ISO format,
  and locale-aware display

# Multi-file edits
> Rename the "UserProfile" component to
  "AccountProfile" across all files

# Gemini CLI shows the diff:
--- a/src/services/user.ts
+++ b/src/services/user.ts
@@ -15,6 +15,12 @@
 async function fetchUser(id: string) {
+  try {
     const response = await api.get(`/users/${id}`);
     return response.data;
+  } catch (error) {
+    if (error.status === 404) {
+      throw new UserNotFoundError(id);
+    }
+    throw new ApiError('Failed to fetch user', error);
+  }
 }

Apply changes? [y/n/e(dit)]: y
 Changes applied to src/services/user.ts

Running Shell Commands

Gemini CLI can execute shell commands as part of its workflow. It always asks for permission before running commands:

Shell Command Examples
# Run tests
> Run the test suite and fix any failing tests

# Build the project
> Build the project and fix any compilation errors

# Install dependencies
> Install the axios library and update the imports

# Gemini CLI asks permission:
I'd like to run: npm test
Allow? [y/n]: y

Running npm test...
PASS src/utils/date.test.ts
FAIL src/services/user.test.ts
  ✗ should handle missing user gracefully

I see a failing test. Let me fix it...

Tool Use

Gemini CLI uses built-in tools to interact with your development environment:

Tool Purpose Example
Read File Read contents of a file Reading source code, configs, docs
Write File Create or modify files Editing code, creating new files
Shell Execute terminal commands Running tests, builds, git commands
Search Search files and content Finding functions, patterns, usages
Web Search Search the internet Looking up docs, error messages

Sandbox Mode

Sandbox mode restricts Gemini CLI's ability to modify files and run commands, making it safe for exploration:

Terminal
# Start in sandbox mode (read-only)
$ gemini --sandbox

# In sandbox mode, Gemini CLI can:
 Read files and understand your codebase
 Answer questions about your code
 Suggest changes (shown but not applied)
 Search for patterns and dependencies

# In sandbox mode, Gemini CLI cannot:
 Modify or create files
 Run shell commands
 Install packages
When to use sandbox: Use sandbox mode when exploring an unfamiliar codebase, during code review sessions, or when you want to ask questions without any risk of changes. It is a great starting point for new projects.

Context Management

Managing context effectively helps Gemini CLI provide better responses:

Context Commands
# Reference specific files in your prompt
> Look at src/auth/login.ts and add rate limiting

# Start a new conversation (clear context)
> /clear

# Check current context usage
> /status

# Focus on specific directories
> Only look at files in the src/api/ directory
  and tell me about the endpoint structure

💡 Try It: Explore Your Codebase

Start Gemini CLI in sandbox mode in one of your projects and try these commands: (1) Ask what the project does, (2) Find all functions that handle errors, (3) Ask for a summary of the project's dependencies. Compare the responses with your own understanding of the project.

Sandbox mode is the safest way to explore what Gemini CLI can do without any risk of modifying your code.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.