GitHub CLI

The command cheatsheet

0 / 180%

1. Install GitHub CLI & log in

Install the GitHub CLI (gh) on Windows using winget, then log in so gh can talk to your GitHub account.

  1. 1
    $gh --version

    Check if the GitHub CLI is already installed. If you see a version number, skip to step 4.

    Example output
    gh version 2.55.0 (2024-08-28)
  2. 2
    $winget install --id GitHub.cli

    Install GitHub CLI using Windows' built-in package manager. Accept any prompts. Close and reopen your terminal after it finishes.

  3. 3
    $gh --version

    Run again to confirm the install worked. You should now see the version.

    Example output
    gh version 2.55.0
  4. 4
    $gh auth login

    Start the login flow. gh will ask you a few questions in the terminal.

  5. 5
    $GitHub.com → HTTPS → Login with a web browser

    Pick these answers when prompted. Copy the one-time code shown, press Enter, paste the code in the browser and authorize.

    Example output
    ! First copy your one-time code: ABCD-1234
    Press Enter to open github.com in your browser...
  6. 6
    $gh auth status

    Verify you're logged in. It should show your username and 'Logged in to github.com'.

    Example output
    ✓ Logged in to github.com as Gongchampou (keyring)
    ✓ Git operations for github.com configured to use https protocol.

2. Create your project & push to GitHub

Make a folder, turn it into a Git repo, make your first commit, then create a matching repo on GitHub and push — all from the terminal.

  1. 1
    $mkdir

    Create a new folder (use any project name — set yours in the box).

  2. 2
    $cd

    Move into that folder. Every command after this runs inside it.

  3. 3
    $dir

    List files in the folder (Windows). It'll be empty for now — that's fine.

  4. 4
    $git init

    Turn this folder into a Git repository. A hidden .git folder is created to track changes.

    Example output
    Initialized empty Git repository in C:/Users/you/kamei/.git/
  5. 5
    $git status

    See what Git sees: which files are new, changed, or ready to commit.

  6. 6
    $git add .

    Stage every file in the folder — tells Git 'include these in my next commit'.

  7. 7
    $git commit -m "xxx"

    Save a snapshot with a message. Replace 'xxx' with a short description of what you did.

    Example output
    git commit -m "first commit: add README"
  8. 8
    $gh repo create --private --source=. --remote=origin --push

    Create a PRIVATE repo on GitHub named after your project, link it as 'origin', and push your commits.

    altgh repo create --public --source=. --remote=origin --push
  9. 9
    $git remote -v

    Confirm the GitHub URL is linked. You should see 'origin' pointing at your new repo.

    Example output
    origin  https://github.com/Gongchampou/kamei.git (fetch)
    origin  https://github.com/Gongchampou/kamei.git (push)

Extra — delete a repo from the CLI

Cleaning up? You can delete the GitHub repo and remove Git tracking from your local folder.

  1. 1
    $gh repo delete OWNER/REPO

    Delete a repo on GitHub. Replace OWNER with your username and REPO with the repo name.

    Example output
    gh repo delete Gongchampou/kamei
  2. 2
    $Remove-Item -Recurse -Force .git

    Remove the hidden .git folder so the local folder is no longer a Git repo. Your files stay.

  3. 3
    $gh repo list

    Show your remaining GitHub repos to double-check the deletion worked.

Tip: run these one at a time — read each command's output before typing the next. If something errors, copy the message and search it.

Interactive

The CLI Playground

Practice real Git and GitHub CLI commands. Nothing installs, nothing breaks. Try help to start.

~/practice — git playground
Welcome to the GitHub CLI Playground 🎉
Type `help` and press Enter to see all commands.
$

The playground simulates Git for learning — it doesn't touch any real repository.