Step-by-step
🤖 GitHub Copilot
GitHub
📘 Step-by-step guide 📘 GitHub · GitHub Copilotbeginner 🔄 Life & Business

Automate Git Commands with GitHub Copilot Suggestions

Discover how to use GitHub Copilot to suggest and run everyday Git commands, helping you manage your project's changes without memorising complex technical codes.

If you've ever felt overwhelmed by the precise commands needed to save and organise your programming work, or simply track changes to any project, you are not alone. This guide will show you how to let GitHub Copilot do the heavy lifting, turning your natural language requests into ready-to-use Git commands directly inside your code editor. It’s like having a helpful assistant for your project's version control.

✅ Before you start
  • Visual Studio Code (VS Code): A popular, free code editor. Ensure you have it installed on your computer.
  • GitHub Copilot Subscription: GitHub Copilot is a paid service. Make sure you have an active subscription for Copilot and Copilot Chat.
  • VS Code Extensions: Install the GitHub Copilot and GitHub Copilot Chat extensions within VS Code. You can find these in the Extensions view (a square icon on the side panel).
  • Time: This guide will take approximately 10-15 minutes to follow through.

First, let's clarify two essential terms. Git is a version control system—think of it as a digital time machine for your project files, keeping track of every change so you can undo mistakes or explore different versions. The terminal (or command line) is a text-only window where you type direct instructions to your computer, rather than clicking buttons, like giving specific commands to a digital assistant.

1

Open your project and the terminal

To begin, we need to open your project folder in your code editor and access the built-in terminal. This lets you ask for help and run commands exactly where you're working.

Open Visual Studio Code and use the "File" menu (top-left) to select "Open Folder...", then navigate to and select your project folder. Once open, you'll see your project files listed on the left. Next, open the integrated terminal: look for the "Terminal" menu at the top of VS Code and select "New Terminal." A new panel will appear at the bottom of your screen, showing a text-based input area. If your screen looks different, you might find a plus (+) icon within the bottom panel that creates a new terminal, or try the keyboard shortcut Ctrl + \`` (backtick) on Windows or Cmd + `` on a Mac.

You'll know it worked when: The bottom panel opens and shows a text prompt, usually ending with $ or > and your current folder name.

2

Ask Copilot for a basic save command

In Git, a commit is like saving a checkpoint in a video game, marking a specific set of changes to your project. Before you commit, you usually stage your changes, which means preparing them to be included in that checkpoint—think of it like packing items into a box before sealing it. Instead of trying to remember the exact commands to stage and save your files, you can just ask Copilot.

With your terminal open, you'll see a prompt where you can type. Instead of typing a Git command, look for a Copilot icon, or a small text box within or above the terminal panel that says "Ask Copilot." Click on this or use the shortcut Ctrl + I (or Cmd + I on Mac). A small input field will pop up, ready for your question. What happens next is Copilot listens to your natural language. If it looks different, you might need to make sure the "GitHub Copilot Chat" extension is enabled, or simply start typing in the main terminal prompt, and Copilot might automatically offer suggestions after you type a few words or trigger it with /git.

💬 ExampleType: *"How do I stage all changes and commit them with the message 'Added initial project setup'?"*

You'll know it worked when: The Copilot chat box or inline suggestion area shows a generated command, likely starting with git add . && git commit -m "...".

3

Run Copilot's suggested command

Once Copilot has generated a command for you, the next step is to run it in your terminal. This is where your instructions come to life and Git performs the action.

After Copilot suggests the command, you'll usually see a button or an option to "Insert" or "Run" the command. For example, a small button labelled "Insert into Terminal" or a right-arrow icon might appear next to the suggestion. Click this button to place the command into your terminal's input line. What happens next is the command will appear in your terminal, ready to be executed. Press the Enter key on your keyboard. If it looks different, sometimes Copilot might directly offer a "Run Command" button, which will execute it immediately without you pressing Enter. Always review the command before running it.

You'll know it worked when: The terminal shows messages indicating success, such as "[main (root-commit) ...] Added initial project setup" or "2 files changed, 10 insertions(...)", and your files have been saved in Git's history.

4

Create a new "sandbox" (Git Branch)

A branch is like creating a parallel universe or a separate workspace for your project. It lets you safely test new ideas or build new features without messing up the main, working version of your website or application. You can switch between branches easily, keeping your experiments separate until they're ready.

Open the Copilot chat box in your terminal again (either by clicking its icon or using Ctrl/Cmd + I). Now, ask Copilot to help you set up a new isolated space for your work. What happens next is Copilot will suggest the Git command to create and switch to this new branch in one go. If it looks different, ensure your Copilot Chat panel is visible; you might need to expand the bottom panel further to see it clearly, or just type your request directly into the main terminal prompt and wait for the inline suggestion.

💬 ExampleType: *"Create a new branch and switch to it, name it 'feature/contact-page-update'."*

You'll know it worked when: Copilot suggests a command similar to git checkout -b feature/contact-page-update, ready for you to insert and run.

5

Safely combine your work (Git Merge)

Once you're happy with your changes in your sandbox branch (e.g., feature/contact-page-update), you'll want to bring them back into your main project. This process is called merging. Copilot makes this safe by reminding you of the correct order of steps, ensuring you don't accidentally overwrite your hard work.

Trigger the Copilot chat in your terminal once more. In the prompt, explain what you want to achieve. What happens next is Copilot understands that merging often involves a sequence of commands (first switching back to your main branch, then performing the merge). It will provide you with clear, distinct commands to follow. If it looks different, or Copilot only gives you one command, you can refine your prompt by asking: "Can you give me the full sequence of commands to merge...?"

💬 ExampleType: *"How do I merge my current branch (feature/contact-page-update) back into the main branch?"*

You'll know it worked when: Copilot suggests a sequence, typically starting with git checkout main followed by git merge feature/contact-page-update, ensuring a smooth process.

⚠️ Common mistakes
  • Blindly running commands: Always read the command Copilot suggests before pressing Enter or the "Run" button. While AI is incredibly helpful, it doesn't know your project's specific history or nuances as well as you do. Fix: Take a moment to read the command and understand what git add, git commit, git checkout, or git merge actually do. If unsure, ask Copilot: "Can you explain what this command means?"
  • Forgetting your location: Before running a command to save or merge, make sure you are in the correct project folder in your terminal. Running Git commands in the wrong folder can lead to errors or applying changes to the wrong project. Fix: If you're unsure, ask Copilot: "How do I check which folder I am currently in?" or simply type pwd (print working directory) and press Enter to see your current path.
  • Not providing enough context: If Copilot gives a generic or unhelpful suggestion, it might not have enough information about your goal. For instance, just saying "merge" isn't as helpful as "merge my 'feature/design' branch into the 'main' branch." Fix: Be specific with your requests, mentioning branch names, commit messages, or what files you've changed.
🚀 Try it now

Let's do a quick test. Open Visual Studio Code and your project's integrated terminal. Trigger the Copilot chat (click its icon or Ctrl/Cmd + I), and then type: "How do I check the status of my current files?"

Watch how quickly it suggests git status—the foundational command to see what changes are pending or have been made in your project. This simple command is your first step to understanding your project's current state with Git, and Copilot helps you find it instantly.

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

← Back to all stories