Gemini CLI Tutorial #3 - Making Code Changes

Net Ninja · Beginner ·🧠 Large Language Models ·6mo ago

Key Takeaways

The video demonstrates how to use the Gemini CLI to make code changes, specifically extracting templates from a homepage into reusable UI components, and updating the homepage to use these new components. The Gemini CLI is used to create a new branch, add a components folder, and generate the UI components using a prompt.

Full Transcript

All right then, my friends. In the last lesson, we made a Gemini markdown file which can now be used by the Gemini CLI as additional instructions and context whenever we ask it to do something like make code changes or new components or whatever else. And that's what we're going to do in this lesson. We're going to ask it to make a new simple UI component. And that component is going to be a card component. So, if we look on the homepage and scroll down a little bit, we can see these three cards right here for the site features. and then three more cards below that for some popular food combos. And all of this template code is currently written directly in the homepage component where the template gets repeated for each one. Now, I think it would be better in this case to make either one or two reusable card components where we define the template once then just reuse that component multiple times in the homepage for these things. And that way we're going to have much less code duplication. So in this lesson we're going to ask Gemini to do that for us. Okay. Okay, so before we begin, I want to say that I've already switched to a new branch to work on called Gemini/Card. And that way, if things go south, I can just delete the branch and return to the main one, which remains untouched. And this is something I always do when I'm using AI to generate code and work on my project because then I'm just keeping my main codebase safe. Also, I've created a new components folder inside the app folder, so I can tell Gemini to make any new UI components in there. So, the current template for all the cards is currently in the index page component inside this pages folder. And if you open that up and scroll down a bit, you're going to see a bunch of feature cards. And if you scroll down even more, you're going to see a bunch of combo cards. So, these are the things I want to extract into separate UI components so we don't have a load of duplication in this file. And then those components can be used here instead. So then I'm going to keep this file open so it automatically gets added to the session context when I ask Gemini to make this component and that way it can see directly what template needs to be extracted and replaced. But I am going to close this file tree down and come back to the chat window in this other side panel. And then I'm just going to paste in a prompt so you don't have to watch me type this all out from scratch. And it says in the homepage there's currently three feature cards and three combo cards. Can you extract the templates or styles of these two types of cards into reusable UI components called feature card and combo card? They should be made in the app components directory. Then update the homepage to use these card components in the places they're needed. So then now let's cross our fingers, hit enter, and see what happens. [music] Okay. And right now you can see it's asking for permission to make a directory. Now, although we auto accepted edits before, we didn't accept this thing right here, which was to make a new directory. So, you can either allow this once or yes, allow always, which is what I'm going to do right now. >> [music] >> All right. So now that's done and you can see it's made two new cards, the feature card and the combo card. And it actually ran tests for those as well. So it did that of its own accord. I didn't ask it to write any test which is sometimes a little bit annoying. Uh but either way it's created tests and it's also created the components. So let's just have a little look at the code now just to make sure that everything looks okay. So this is the homepage and you can see where we used to have the template hardcoded, we've now got these feature cards instead. So that's good. We've got three of those and we've got three combo cards down there. Now if we open up the file tree, we should see those two components right here. So the combo card and that looks pretty much the same as what it was when it was just coded inside the index file. And you can see we're taking these props, the title, description, and tags and we output those right here. Okay, that looks good. And then the other one is the feature card. And this time we're just taking the title and we have that title right there. We have a slot for the icon and also just a generic slot as well. So let's go back to the homepage and have a look how this was done. All right. Yeah. So there is the icon slots and then the rest of the content just gets rendered right here. So that looks pretty good. And I always like to do this. I always like to check the code that the AI model produces because sometimes it's not right. Sometimes I would do something different, but that looks all good to me. So, let's try this out in a browser. All right. So, if we scroll down, then everything looks at first glance to be the same, which is good. That's what we wanted. We didn't want it to do anything fancy, change the styles or the template or anything like that. We just wanted it to extract the template code from the homepage and put it into reusable components. So, I'm pretty happy with that. Okay. So, I'm happy with these changes then. And at this point, I'd make a commit. And if there were no other code changes needed, I might push up this branch and merge it. So I can open the source control panel over here to do that, which is currently listing all the file changes. Then I'll click on this little twinkle icon to let Copilot this time make a commit message for me because I'm super lazy. Once it's done that, I'll make the commit and push this new branch up to my repo. And then after this lesson, offscreen, I might merge that branch and pull down the new code down into my local project. But anyway, that was a simple enough thing to do, right? We got Gemini to pull out the card templates, make new reusable card components with those templates, and then use them in the homepage. Now, a lot of the time I might not be completely happy with the code changes it makes, and I'll either go through a bunch of further prompts and revisions with the CLI or go into the weeds myself and update the code manually. And if things go off track too much, I can just delete the branch and start again. Anyway, we'll be making more code changes as we go through the series. But first, in the next lesson, I want to talk a little bit about commands and settings in the Gemini CLI.

Original Description

In this Gemini CLI Crash Course series, I'll show you how to get up an running wth the CLI in a project, use extensions & MCP servers, add an API key to access Gemini 3 models and more. 🍿👇 Get early access to the course on NetNinja.dev: https://netninja.dev/p/gemini-cli-tutorial 🔥👇 Get access to premium courses with Net Ninja Pro: https://netninja.dev/p/net-ninja-pro/#prosignup 🔥👇 Git & GitHub Masterclass: https://netninja.dev/p/git-github-masterclass 🔗👇 Starter Project on GitHub: https://github.com/iamshaunjp/gemini-cli-course 🔗👇 Gemini CLI docs: https://geminicli.com/docs/ 🔗👇 Gemini CLI Extensions: https://geminicli.com/extensions/ 🔗👇 Context7 https://context7.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This video teaches how to use the Gemini CLI to extract templates from a homepage into reusable UI components and update the homepage to use these new components. The lesson covers branching, adding a components folder, generating UI components using a prompt, and committing changes.

Key Takeaways
  1. Create a new branch to work on
  2. Add a components folder to the project
  3. Open the homepage file to add context to the Gemini CLI session
  4. Paste a prompt into the Gemini CLI to generate UI components
  5. Allow the Gemini CLI to make a new directory
  6. Review the generated code and test it in a browser
  7. Commit changes using Copilot
💡 The Gemini CLI can be used to make code changes and generate UI components, but it's essential to review the generated code and test it thoroughly.

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →