Β· Copilot X Β· 3 min read

GitHub Copilot X CLI is your new GIT assistant

Need some help with your git commands? Ask Copilot CLI!

Need some help with your git commands? Ask Copilot CLI!

GitHub Copilot CLI comes with three aliases:

  • ??: Ask for a generic shell command
  • git?: Ask for a git command
  • gh?: Ask for a GitHub CLI command

Today I play with git? to test how accurate the suggestions are and how easy it is to get the right command. You can find the video here, or at the end of the post

Spoiler: if you run AI generated commands without understanding what they do, the outcome is… unpredictable πŸ˜…

Unharmful example

At the beginning of the video you’ll see me asking a pretty simple question, basically creating a new branch from main.

The suggested code is:

git switch -c <branch> main

I’m happy so I run the command and…

(eval):1: no such file or directory: branch

Wait, what? Ah, I forgot to replace <branch> with the actual branch name πŸ€¦β€β™‚οΈ

This was entirely my fault but luckily nothing bad happened, I revised the query and set the right name.

Potentially harmful example

However, later in the video I try to move and remove commits and the first suggestion is:

git reset --hard HEAD~1

Imagine running it without understanding what it does… ok sure, with reflog you can recover the lost commit but if you’re unaware of that you’ll probably just panic because of all the changes you just lost. Doesn’t seem like a cool situation to be in.

Actually, while writing this article I realized I could have just asked this in the video:

git? recover the last hard reset commit

I did it now and the first suggestion is:

 ──────────────────── Command ────────────────────

git reflog
git reset --hard HEAD@{1}

 ────────────────── Explanation ──────────────────

β—‹ git reflog lists all commits that are no longer referenced by any branch.
β—‹ git reset resets the current branch to a previous commit.
  β—† --hard means that we also discard any changes made to the files in the working directory.
  β—† HEAD@{1} specifies that we reset to the commit one before the current one.

If you just didn’t remember the syntax, this is great, but if you’re not sure what you’re doing… imagine being told by an AI that to restore a hard reset you need to do another hard reset. Wouldn’t that be scary? Let me know what you think!

Fun fact

I didn’t realize I had Copilot Voice turned on when I started recording the video. At some point I said something like:

I’m on a branch called copilot-x-test, but is it correct?

And after a second I heard a voice coming out from my speakers:

It depends on the task. You should make sure that the task is valid and reliable before taking it

Aaaah it was Copilot Voice!

Full Demo

Anyway, here’s the full video where I play with Copilot X CLI, asking for git commands and giving you my personal thoughts on the AI generated suggestions.

About the author
Leonardo

Hello! My name is Leonardo and as you might have noticed, I like to talk about Web Development and Open Source!

I use GitHub every day and my favourite editor is Visual Studio Code... this might influence a little bit my conent! :D

If you like what I do, you should have a look at my YouTube Channel!

Copilot X (4 Parts Series)
You might also like
Back to Blog