Skip to main content

Command Palette

Search for a command to run...

From Github Codespaces to Repository: Step-by-Step Setup

Updated
2 min read
From Github Codespaces to Repository: Step-by-Step Setup
A

I'm a passionate software developer.

Introduction

Context

By default, Codespace is using the GITHUB_TOKEN env var (the “Codespaces token”), which can’t create repos.

It’s necessary to authenticate gh with a token/account that has the right scopes, or create the repo on the web first.

Objective

In this article, let’s focus on authenticating, setting the right scopes and creating the repo.


Solution

Initiate the project

In short: we’ll check status → create repo → stage everything → commit it.

git status || git init
git add .
git commit -m "init"

git status → shows the current state of the repository (which files are changed, staged, or untracked).

git init → initializes a new Git repository in the current folder.

git add . → stages all changes (new, modified, deleted files) in the current folder for the next commit.

git commit -m "init" → creates a commit with the message "init".


Check the environment

In short: we’ll log out of the GitHub CLI, then clear the token stored in our environment.

gh auth logout -h github.com
unset GITHUB_TOKEN
  • gh auth logout -h github.com → logs you out from GitHub CLI (gh) specifically for the host github.com.

  • unset GITHUB_TOKEN → removes the GITHUB_TOKEN environment variable from your current shell session.


Login

In short: you log in via browser, then check if the login worked.

gh auth login -h github.com -p https -w
gh auth status
  • gh auth login -h github.com -p https -w → logs you in to GitHub CLI (gh) for the host github.com, using HTTPS as the protocol (-p https), and opens a web browser (-w) to complete the authentication.

  • gh auth status → shows your current GitHub CLI authentication status (which account you’re logged in with, token details, active host, etc.).


Double check login


gh auth status
gh api user



Create and push

In short: this creates a new private repo on GitHub and immediately pushes your local project there.

gh repo create alexcalaca/profile-card --private --source . -
-remote origin --push

Output


Done


More from this blog