LinuxCommandLibrary

gh-codespace

Manage GitHub Codespaces

TLDR

Create a codespace in GitHub interactively

$ gh codespace create
copy

List all available codespaces
$ gh codespace list
copy

Connect to a codespace via SSH interactively
$ gh codespace ssh
copy

Transfer a specific file to a codespace interactively
$ gh codespace cp [path/to/source_file] remote:[path/to/remote_file]
copy

List the ports of a codespace interactively
$ gh codespace ports
copy

Display the logs from a codespace interactively
$ gh codespace logs
copy

Delete a codespace interactively
$ gh codespace delete
copy

Display help for a subcommand
$ gh codespace [code|cp|create|delete|edit|...] --help
copy

SYNOPSIS

gh codespace <command> [flags]

Common commands include:
gh codespace create [flags]
gh codespace list [flags]
gh codespace delete <codespace-name> [flags]
gh codespace ssh <codespace-name> [flags]
gh codespace cp <source> <destination> [flags]
gh codespace ports [flags]

PARAMETERS

create
    Creates a new codespace, often by specifying a repository, branch, or machine type. This command provisions a new cloud development environment.

list (ls)
    Lists all your available codespaces, showing their status, associated repository, machine type, and other relevant details.

delete (rm)
    Deletes one or more specified codespaces, effectively terminating the cloud environment and stopping any associated billing.

stop
    Stops a running codespace, pausing its active session and typically halting billing for compute resources.

start
    Starts a stopped codespace, making it accessible again for development.

ssh
    Connects to a specific codespace via SSH, providing direct command-line access within the cloud environment.

cp
    Copies files or directories between your local machine and a codespace, similar to the scp command.

view
    Displays detailed information about a specific codespace, including its URL, current status, and configuration.

ports
    Lists and manages forwarded ports within a codespace, allowing access to web services or applications running inside the codespace from your local machine.

rebuild
    Rebuilds a codespace, typically used after changes to its devcontainer.json configuration or to refresh the environment.

logs
    Accesses and displays logs from a codespace, which is useful for debugging issues within the environment.

DESCRIPTION

The gh codespace command set within the GitHub CLI provides a comprehensive interface for interacting with GitHub Codespaces. It allows users to perform various operations such as creating new codespaces, listing existing ones, stopping and starting them, deleting them, and connecting to them via SSH. Furthermore, it supports file transfer, port forwarding, and viewing codespace logs, making it a powerful tool for developers who rely on cloud-based development environments, streamlining their workflow directly from the terminal.

CAVEATS

Using gh codespace requires the GitHub CLI (gh) to be installed and properly authenticated with your GitHub account. As Codespaces are cloud-based, continuous network connectivity is essential for their operation. Users should also be aware that GitHub Codespaces incur billing based on usage, and appropriate GitHub permissions are necessary for creating and managing these environments.

INTEGRATION WITH VS CODE

Many gh codespace operations, such as creating or opening a codespace, are designed to integrate seamlessly with Visual Studio Code. This allows users to open their codespaces directly in VS Code desktop or web, providing a familiar and powerful IDE experience.

REMOTE DEVELOPMENT FACILITATOR

This command significantly facilitates remote development workflows. It enables developers to work on projects within pre-configured, cloud-based environments, ensuring consistency across teams and providing all necessary tools and dependencies without the overhead of local setup.

HISTORY

GitHub Codespaces emerged as a cloud-powered development environment solution from GitHub, aiming to provide instantly ready-to-code workspaces. The integration of gh codespace into the GitHub CLI was a natural progression, allowing developers to seamlessly manage these environments directly from their terminal. This development was driven by the need to streamline remote and cloud-based development workflows, making it easier to spin up, access, and tear down development environments without leaving the command line.

SEE ALSO

gh(1), gh auth(1), gh repo(1), ssh(1), scp(1)

Copied to clipboard