Exploring the Gemini CLI
I have just started working with the Gemini CLI, and here are a few things I discovered that helped me be more productive. I you haven't tried out the Gemini CLI, consider doing that! The free tier is very generous. Here's how to install the tool:
npm install -g @google/gemini-cli
gemini
Here are six things I discovered this week:
1. Provide Context First
Always start your session by giving Gemini context about your project. If your very first prompt is something like the following, you’ll be off to a great start.
Example prompt: "Read the source code and identify all files relevant to ..." (add the task you're about to do)
2. Start with a Plan
Instead of jumping straight into coding, begin by outlining your goal and collaborating on a plan. This helps you be more specific in your instructions, which leads to better results.
Example prompt: "I want to implement feature X. Let's discuss it together and create an implementation plan before you start coding."
3. Create Strong Feedback Loops
Context is everything. The more relevant information you provide, the better it can assist you. Don't copy and paste errors, make sure Gemini sees them before you do!
- Add Unit Tests: Insist on including tests to verify your code's functionality. You can run them in the CLI or tell Gemini to run them after it makes changes.
- Add Extensive Logging: Ask Gemini to add detailed logging to track the execution flow and spot issues more easily.
- Execute Directly in the CLI: Use the
!
prefix to run your server or scripts from the command line (for example,!python your_script.py
). Your next prompt can be, "Fix that error."
4. Don’t Fear the Esc Button
Don't be afraid to reject a suggestion if it doesn't seem right. You are in control of the process.
- Hit
ESC
: If Gemini proposes an action (like writing a file or generating code) that you think is on the wrong track, press theESC
key to cancel it. - Continue the Conversation: After canceling, guide it toward a better solution. For instance, you could say, “That doesn’t seem right, can you do a web search first?” Gemini will pick up where it left off.
5. Your On-Demand Scripting Expert
Use Gemini to generate shell commands you can't quite remember. This saves you from having
to search for the right syntax and flags. If it doesn't seem to know the command, just tell
it to figure it out through using the --help
flag.
Example Prompt: "Write a bash script to convert all .HEIC
files in the current
directory to .jpg
and resize them to a maximum width of 1200 pixels."
6. Finish the task with Git: Commit and Push
When you've finished implementing a feature, you can hand off the entire Git workflow. Gemini will:
- Summarize the work completed.
- Check the
git status
. - Stage all the new and modified files.
- Write a detailed, conventional commit message based on the context of the tasks it just performed.
- Confirm with you before committing and pushing.
Example Prompt: "Okay, we're done. Please commit and push the changes."