Step-by-step
🤖 GitHub Copilot
GitHub
📘 Step-by-step 📘 GitHub · GitHub Copilot↗ GitHub Copilot · Official sitebeginner 🔄 Life & Business

Generate Basic, Reusable Code Snippets with GitHub Copilot

Learn how GitHub Copilot can write starter code for you — from date formatting to simple API calls — even if you're not a full-time developer.

Hook: By the end of this guide you'll be able to ask GitHub Copilot to draft small, useful code snippets — like a date formatter or a simple form check — and save them in a personal library you can reuse later. It's written for complete beginners, including people who don't code every day but occasionally need a helper script. One honest note up front: Copilot is fast, but it cannot replace careful testing — always read what it writes before relying on it.

💡 Tip: tap a step’s number when you finish it — a green tick appears and your browser remembers how far you got.

✅ Before you start
  • A free GitHub account (sign up at github.com if you don't have one).
  • A computer running Windows, macOS or Linux.
  • Visual Studio Code installed — a free code editor from Microsoft. If you don't have it yet, download it from the official Microsoft site and follow the installer.
  • GitHub Copilot: there's a Free tier with a limited monthly allowance of suggestions and a paid Pro plan (around $10 USD/month) for unlimited use. Some features may need the paid plan — we'll flag that where it matters.
  • About 15 minutes for the whole walkthrough.
1

Install the GitHub Copilot extension

Open Visual Studio Code and look at the left-hand sidebar — a column of icons. Click the icon that looks like four small squares (this is the Extensions view). A panel slides open on the left; in the search box at the top, type GitHub Copilot. Look for the result published by GitHub itself, with the name "GitHub Copilot" — there are many similar-sounding extensions, so pick the official one. Click the blue Install button next to it. After a few seconds you'll see a small Copilot icon appear in the bottom status bar of VS Code. If your sidebar looks different, open the View menu at the top and choose Extensions instead, then search the same way. You'll know it worked when the Copilot icon in the bottom bar is no longer greyed out.

💬 Examplesearch term — `GitHub Copilot`
2

Sign in to your GitHub account

Click the new Copilot icon in the bottom status bar (or look for Accounts in the bottom-left corner of VS Code). A popup appears asking you to sign in. Click Sign in to GitHub — your default web browser will open on a GitHub login page. Type your username and password, then approve the connection when GitHub asks. Return to VS Code; you'll see your GitHub avatar appear in the bottom-left where the Accounts menu used to show "Sign in". If the popup doesn't appear, open the Command Palette by pressing Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS, then type Copilot: Sign in and press Enter. You'll know it worked when your avatar and username appear in the bottom bar and the Copilot icon turns into a coloured symbol.

💬 Examplecommand — `Copilot: Sign in`
3

Create a new file in the language you want

Open the File menu at the top of VS Code and choose New File (or press Ctrl+N on Windows/Linux, Cmd+N on macOS). When prompted, save the empty file with a name that ends in a language extension — for example snippet.js for JavaScript, snippet.py for Python, or snippet.html for HTML. The extension helps Copilot understand what kind of code to suggest. As soon as you save, the bottom-right corner of VS Code will show the language name (like "JavaScript" or "Python"). If you don't see that language hint, click the words in the bottom-right corner and pick your language from the popup list manually. You'll know it worked when the file is saved on your computer and the language label appears in the bottom-right.

💬 Examplefilename — `my-snippets.js` or `my-snippets.py`
4

Describe the snippet you want in a comment

Click inside the empty file and on the first line, type a comment that describes what you want the code to do in plain English. A comment is a note for humans — the computer ignores it when running the code. In JavaScript and most C-style languages, comments start with //; in Python use #; in HTML use <!-- -->. After you finish typing the comment, pause for a second or two. Copilot will print greyed-out suggestion text right under your comment — this is its best guess at the code you described. The first time you use it, the suggestion may be brief or unusual; that's normal. If no grey text appears, press Enter to start a new line and pause again — Copilot sometimes needs that nudge to "wake up". You'll know it worked when you see light grey code appear beneath your comment.

💬 Example(in a JavaScript file, type this comment exactly): `// Function that takes a date and returns it formatted as DD/MM/YYYY`
5

Accept, refine and save the snippet

With the grey suggestion visible, press the Tab key — this accepts the suggestion and turns it into real, coloured code in your file. Read it carefully: Copilot is helpful but not perfect, and sometimes it invents a function name or syntax that doesn't quite match your needs. To reject the suggestion, press Esc or just keep typing; your new text will replace the grey text. To ask for a different version, add another comment below the suggestion explaining what to change, then pause again. Once you're happy with a snippet, save the file with Ctrl+S / Cmd+S and keep it in a folder called something like snippets on your computer — that's your personal reusable code library. You'll know it worked when you have a fully coloured block of working code in your file and you can copy it into other projects later.

💬 Examplerefinement comment: `// also handle leap years`
⚠️ Common mistakes
  • Treating every suggestion as correct. Copilot writes plausible-looking code that sometimes doesn't actually run. Fix: Read the suggested code line by line before saving, and test it in a small example before relying on it in a real project.
  • Hitting the free-tier limit. On GitHub Copilot Free you get a small monthly allowance of completions and chats; once it's used up, the tool will stop suggesting until next month. Fix: Use the suggestions wisely on real tasks, or upgrade to a paid Pro plan if you need unlimited use.
  • Asking for something too vague. Writing a comment like "make a website" gives Copilot very little to work with and usually produces nonsense. Fix: Be specific — describe the inputs, the output, and any constraints (for example: "a function that takes a list of emails and returns only the ones ending in .com").
🚀 Try it now

Open VS Code, create a new file called today.py, and type this comment on the first line: # print today's date in the format YYYY-MM-DD. Pause for two seconds, then press Tab if a grey suggestion appears. Save the file. You've just generated your first reusable snippet — and you can copy it into any future Python project.

❓ Quick questions

How long does this take?

About 6 minutes — the guide has 5 steps, and you can tick each one off as you go.

Which tool do I need?

This guide uses GitHub GitHub Copilot — but the approach works very similarly in other AI assistants.

Do I need to prepare anything?
  • A free GitHub account (sign up at github.com if you don't have one).
  • A computer running Windows, macOS or Linux.
  • Visual Studio Code installed — a free code editor from Microsoft. If you don't have it yet, download it from the official Microsoft site and follow the installer.
  • GitHub Copilot: there's a Free tier with a limited monthly allowance of suggestions and a paid Pro plan (around $10 USD/month) for unlimited use. Some features may need the paid plan — we'll flag that where it matters.
  • About 15 minutes for the whole walkthrough.
What mistakes should I avoid?
  • Treating every suggestion as correct. Copilot writes plausible-looking code that sometimes doesn't actually run. Fix: Read the suggested code line by line before saving, and test it in a small example before relying on it in a real project.
  • Hitting the free-tier limit. On GitHub Copilot Free you get a small monthly allowance of completions and chats; once it's used up, the tool will stop suggesting until next month. Fix: Use the suggestions wisely on real tasks, or upgrade to a paid Pro plan if you need unlimited use.
  • Asking for something too vague. Writing a comment like "make a website" gives Copilot very little to work with and usually produces nonsense. Fix: Be specific — describe the inputs, the output, and any constraints (for example: "a function that takes a list of emails and returns only the ones ending in .com").

Keep reading

📬 The week’s AI, in your inbox

One friendly email every Sunday — the 5 stories that mattered, in plain English. No spam, unsubscribe anytime.

Was this helpful?

✦ Original step-by-step guide by AI World HQ's AI editorial team. Written in plain language, reviewed for accuracy.

← Back to all stories