GitHub’s CLI tool turns your Windows command line into a fast, powerful way to interact with repositories, issues, and pull requests without opening a browser. In just three steps—install, authenticate, and test—you’ll have full access to GitHub’s core functions, saving time and reducing browser fatigue. The tool also avoids some Windows quirks (like path inconsistencies) that can trip up traditional Git setups. All you need is Windows 10/11, a GitHub account, and basic command-line familiarity.

What You'll Need

  • A Windows PC running Windows 10 or 11 (GitHub CLI also works on Linux/macOS).
  • A stable internet connection (for the initial download and authentication).
  • Admin or user rights to install software (for Windows).
  • GitHub account credentials (email + access token or OAuth app).

Step-by-Step

  1. Download and install GitHub CLI: Open a browser, visit https://cli.github.com/, and click "Download for Windows". Run the installer as Administrator. During setup, deselect optional features like Git for Windows (optional; the CLI includes its own Git engine). The install takes 1–2 minutes. If rejected by UAC: Right-click the installer > "Run as administrator" and proceed. Verify installation: Open Command Prompt (Win+R > type `cmd` > Enter) and run: gh --version. You should see output like: GitHub CLI v2.30.0. If not, restart your PC and retry.
  2. Authenticate with your GitHub account: In the same Command Prompt, run: gh auth login. Follow the prompts:
    1. Choose a browser tab (or use a different window/tab to avoid conflicts).
    2. Log in with your GitHub email/password.
    3. Select "Web" or "Desktop" (for Windows) and choose "Yes" to allow permissions.
    4. Enter the verification code sent to your email or phone (if enabled).
    Troubleshooting:
    • If prompted for "GitHub App Password" but you didn’t set one, skip to step 3.
    • If the browser tab is stuck, close it and re-run gh auth login.
  3. Test basic commands: Verify access by running: gh repo list to list your public repositories. gh api user to fetch your GitHub user profile. gh issue list --repo=owner/repo to view issues in a sample repo. If you get "Unauthorized": Re-run gh auth login and ensure you’re logged in correctly.
  4. Configure default repository (optional): Set your preferred remote repository (e.g., for a personal project): gh repo clone owner/repo (creates a local copy). Or set it globally: gh config set github.token (not recommended; use gh auth login instead). No token needed for basic use—authentication happens per command.

Common Mistakes

  • Permission errors: Ensure you’re running Command Prompt as Administrator when installing or restarting the CLI. Uninstall via Control Panel > Programs > GitHub CLI and reinstall.
  • Login hangs: Close all browser tabs/windows where GitHub CLI browses. Use a different tab or Device Profile in Chrome/Firefox to avoid conflicts.
  • GitHub token prompts: Avoid manually entering tokens in CLI settings. Use gh auth login instead—tokens are tied to sessions.
  • Outdated CLI: Run gh version to check updates. Update via: gh extension install gh or the official installer.

Tips

  • Use aliases for common tasks: Add these to your ~/.bashrc (or ~/.zshrc for macOS) to speed up workflows: alias ghcl="gh" alias ghshow="gh api user"
  • Save commands to scripts: Create a `.bash` or `.ps1` script file (e.g., `update-repo.ps1`) with commands like: gh repo clone org/repo -- Run it with PowerShell: .\update-repo.ps1. This avoids typing long CLI paths repeatedly.
  • Debug issues: Run gh --debug before commands to see detailed output.
  • Backup CLI: If reinstalling, export your config: gh config export config.yml Restore later with: gh config import config.yml

Troubleshooting

  1. Error: "Command not found": Ensure GitHub CLI is in your PATH: gh --help should return help text. If not, reinstall and check the install location (typically C:\Program Files\GitHub CLI\bin). Windows 11 tip: Add the CLI folder to PATH via: Settings > System > About > Advanced system settings > Environment Variables > Edit > System Variables > Add "C:\Program Files\GitHub CLI\bin".
  2. Login fails with "Invalid credentials":
    1. Verify your GitHub account email is correct in your profile settings.
    2. Ensure you’re not using a personal access token (PAT) without scopes (e.g., `repo`).
    3. Try logging in again with gh auth login and select "Desktop" instead of "Web" (Windows-specific).
  3. GitHub API rate limits exceeded: Wait 60 seconds or reset your token: gh auth logout gh auth login Rate limits apply per IP address—use a VPN if necessary.
  4. Commands don’t recognize GitHub repos: Ensure you’re using the correct command (e.g., gh repo list vs. git ls-remote, which won’t work). Check available commands with: gh help.
  5. Network issues: Test connectivity: ping github.com If blocked by corporate firewalls, use a VPN or contact your IT team.
  6. CLI crashes on startup:
    1. Close all Command Prompt/PowerShell windows.
    2. Delete the CLI cache: rmdir /s /q "$env:LOCALAPPDATA\GitHub" (PowerShell) or manually delete C:\Users\YourUsername\AppData\Local\GitHub.
    3. Reinstall the CLI.

Frequently Asked Questions

1. What if I don’t want to use a personal access token?

You can skip tokens entirely by using OAuth apps. When prompted during gh auth login, select "Desktop" and allow the necessary permissions. No token is stored; authentication happens via your browser.

2. Can I use GitHub CLI on Windows Server?

Yes, but with limitations. The CLI works in a VM or on a desktop, but server environments may lack GUI-based prompts (e.g., for browser-based login). Use gh auth login in a script with saved credentials (tokens) instead of interactive prompts.

3. How do I switch between GitHub accounts?

Use: gh auth switch to log in with another account. For multiple accounts, add scopes like repo:full during the first login to avoid re-prompting.

4. What’s the difference between CLI and GitHub Desktop?

GitHub CLI is command-line only, while Desktop provides a graphical interface for local repos and pull requests. CLI is faster for automation and scripting; Desktop is better for visual workflows.

5. Can I use GitHub CLI for private repositories?

Yes, but you need a personal access token with `repo` scope. During gh auth login, select "Desktop" and choose "Private repositories" under the token section.

6. How do I undo a mistake after running a dangerous CLI command?

Most commands are idempotent (safe to retry). For destructive tasks (e.g., gh repo delete):

  1. Verify the target repo: gh repo list
  2. Use the `--yes` flag to confirm: gh repo delete --yes
If you mistakenly deleted a repo, recover it from GitHub’s backup system or via: gh repo restore (available for repos <7 days old).