logo

Gemini CLI Cheatsheet

The official Google Gemini CLI allows you to interact with the Gemini family of models directly from your terminal.

Prerequisites

  • You must have the Go programming language installed.
  • You need a Gemini API Key. Get one from Google AI Studio.

Installation & Setup

Install the CLI:

go install github.com/google/generative-ai-go/cmd/gemini@latest

Set your API Key: (This is a one-time setup)

gemini config set api_key "YOUR_API_KEY_HERE"

Check your configuration:

gemini config list

Basic Interaction

Send a simple prompt:

gemini "Why is the sky blue?"

Send a multiline prompt (using heredoc):

gemini <<EOF
Summarize the key differences between
Ragtime music and early Jazz, focusing on:
1. Improvisation
2. Rhythm
3. Instrumentation
EOF

Stream the response (see it type out live):

gemini -s "Tell me a short story about a robot who discovers music."
# Alias: gemini --stream ...

Set the creativity/temperature (0.0 to 1.0):

  • 0.0: More deterministic, factual.
  • 0.9: Highly creative.
gemini -t 0.8 "Write a poem in the style of Edgar Allan Poe about a lost USB drive."
# Alias: gemini --temp 0.8 ...

Working with Files (Images, Text, PDFs)

This is one of the most powerful features, especially with Gemini 1.5 Pro.

General syntax:

gemini -f <filepath> "Your prompt about the file"

Summarize a text file:

gemini -f README.md "Summarize the purpose of this project."

Describe an image:

gemini -f '~/Pictures/vacation.jpg' "Where might this photo have been taken? Describe the scene."

Analyze a PDF document:

gemini -f 'report.pdf' "What are the top 3 key findings from this report?"

Work with multiple files:

gemini -f code.py -f errors.log "Based on the error log, how would you fix the python code?"

Analyze a CSV file:

gemini -f sales_data.csv "What is the total revenue? Provide the sum of the 'Amount' column."

Model Management

List all available models:

gemini models list

Use a specific model (e.g., Gemini 1.5 Pro):

gemini -m gemini-1.5-pro-latest "This prompt will be answered by Gemini 1.5 Pro."
# Alias: gemini --model ...

Get detailed info about a model:

gemini models info gemini-1.5-pro-latest

Set a new default model for all your queries:

gemini config set default.model gemini-1.5-pro-latest

Chat & History Management

Start an interactive chat session:

gemini chat

(Inside the chat, just type your prompts. Use quit or exit to end the session.)

List your conversation history:

gemini history list

Show a specific conversation from your history:

gemini history show @1d1f02
# The ID (@...) is from the history list

Continue a previous conversation (stateless): This allows you to provide context from a past chat without starting an interactive session.

# First, get the ID from 'gemini history list'
gemini -c @1d1f02 "Based on our last conversation, what's the next logical step?"
# Alias: gemini --continue ...

Tips & Tricks

Piping stdin content to Gemini: This is a classic CLI power-user move.

# Pipe file content
cat main.go | gemini "Explain what this Go code does."

# Pipe command output
ls -l | gemini "Describe this directory structure."```

**Create a shell alias for brevity:**
Add this to your `.bashrc`, `.zshrc`, etc.
```bash
alias g="gemini"

Now you can just run g "Hello"!

Get output in JSON format (for scripting):

gemini --json "List three benefits of using a command-line interface."

Combine multiple flags:

g -s -m gemini-1.5-pro-latest -f photo.png "Write a short, creative story inspired by this image."