'gh' is not recognized... error while trying to create GitHub repo from command prompt
Asked Answered
O

4

49

I'm following the instructions on how to add an existing project to GitHub from GitHub docs. However, I get an 'gh' is not recognized as an internal or external command, operable program or batch file. error message when I try to use gh repo create fs1 command in the project root directory as instructed. Here fs1 is my project name. I browsed StackOverflow but couldn't find any help yet. What am I missing?

Oliva answered 27/8, 2021 at 10:29 Comment(0)
N
53

The page you are following doesn't include the instructions to install the GitHub CLI, so it is likely you don't have it installed (it doesn't come with git as far as I know).

Installation instructions can be found here: https://cli.github.com/

Nicodemus answered 27/8, 2021 at 10:33 Comment(7)
Now the repository got created but I got error: remote origin already exists. error whilte creating it.Oliva
That probably means that the repository name you're trying to create is already one you've created on GitHub, I would check there to be sure you haven't done that. I could be wrong thoughNicodemus
I had fs1 on GitHub earlier but I deleted it to try the creation from command prompt. Now I managed to create it from there, but I get these already exists -type of errors no matter what I try to do with it.Oliva
I think I got it now. I just skipped all the previous steps and continued from git branch -M main and then git push -u origin main. Now mt repo looks like this: fs1Oliva
Just a silly question, but perhaps others will benefit from answer, I assumed because I had installed git, it would enable me to use gh command from Git Bash? However when I try and do gh repo create my-project-name I get bash: gh: command not found. When I run $ git version I get git version 2.33.1.windows.1. Do I have to download and install GitHub CLI from cli.github.com as well as have git installed? And then gh will be available from Git Bash? Update: Yes, that seems to work, was prompted to authenticate with gh auth login beforehand.Atherosclerosis
Mac users can install using brew, brew install ghSheer
Windows users, restart your CMD window, or, preferrably nowadays, Powershell :-) Restart VScode too if you have it open.Grayish
S
16

gh is github cli. Install github cli:

windows

choco install gh

( choco is installed with nodejs most of the time )

mac

brew install gh

for linux: https://github.com/cli/cli/blob/trunk/docs/install_linux.md

ref: https://cli.github.com/manual/installation

Stipulation answered 6/1, 2023 at 14:18 Comment(2)
In most cases, don't forget to restart your terminalWillard
winget install GitHub.cli might be a better command for windows, as winget should be installed by default nowNicodemus
V
5

I had the same issue. I didn't have gh installed.

I installed the gh, but the same error occurred.

I checked the environment variables and gh location was there.

I restarted windows, the error went away :)

Victorvictoria answered 18/5, 2022 at 12:5 Comment(1)
Just restart the terminal is enought. In my case, I'm using node.js so I just closed the node command line and opened a new node command line window and it worked!Phocomelia
B
5

Actually, with Windows 10 or 11, to avoid having to download even more crap, use: winget install --id github.cli

This can be done straight from the VSCode Terminal.

Bughouse answered 15/1, 2023 at 10:57 Comment(2)
Excellent use of winget for Windows 10 and above.Francesfrancesca
Great! Just make sure you restart your terminal after installing it, as some other answer below stated.Feigin

© 2022 - 2024 — McMap. All rights reserved.