Β· Copilot X Β· 3 min read
GitHub Copilot X CLI is your new GIT assistant
Need some help with your git commands? Ask Copilot CLI!
GitHub Copilot CLI comes with three aliases:
??
: Ask for a generic shell commandgit?
: Ask for agit
commandgh?
: 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.
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!
Let's get in touch, feel free to send me a DM on Twitter!