MODULE 2.1 / 2 OF 4

Git, gh, and an SSH key on GitHub

Connect your computer to your GitHub account with an SSH key, create a repository (public or private), and publish the page.

0%0 of 0
01 / OSWORKTell Git who you are02 / OSWORKCreate your SSH key03 / OSWORKConnect gh to your account and send the key04 / OSWORKCreate the repository and upload the project05 / OSWORKPublish the page on GitHub Pages06 / OSWORKYour daily routine
The steps in this module, in the order you’ll type them.
6steps
~20 minhands-on
2/4track
3idiomas · languages

1Tell Git who you are

git config --global user.name "Your Name"
git config --global user.email "you@email.com"
git config --global --list

What you see: user.name=Your Name and user.email=you@email.com in the list.

What it is

Use the same email as your GitHub account. You only need to do this once per computer.

Why learn it

Every saved version includes your name. GitHub uses your email to link versions to your account.

Key concepts

git config: configures Git. --global: applies to all projects on this computer. Commit: a saved version of the project, with an author and message.

2Create your SSH key

ssh-keygen -t ed25519 -C "you@email.com"
explorer %USERPROFILE%\.ssh

What you see: In the .ssh folder: id_ed25519 (private key) and id_ed25519.pub (public key).

What it is

Press Enter at all 3 prompts to accept the default location and continue without an extra password. Then explorer opens the folder where the keys were saved.

Why learn it

An SSH key is your passwordless identity: GitHub and the VPS recognize your computer through it.

Key concepts

SSH: a secure way to connect two computers. Private key: stays on your machine and is never sent. Public key (.pub): the one you give to GitHub and the VPS.

id_ed25519private: staysid_ed25519.pubpublic: shareGitHub and the VPS only receive the .pub file
Two keys, two destinations: the private key never leaves your computer; the public key goes to GitHub and the VPS.

3Connect gh to your account and send the key

gh auth login
ssh -T git@github.com

What you see: Hi YOUR-USER! You've successfully authenticated.

What it is

Answer: GitHub.com → SSH → choose id_ed25519.pub → Login with a web browser. Copy the code, paste it into your browser, and authorize. Then test the key; the first time, answer yes.

Why learn it

One command logs you in and sends your public key to your account, without opening settings on the website.

Key concepts

gh auth login: signs in to your GitHub account from the terminal. SSH protocol: Git starts using your key instead of a password. ssh -T: tests the connection without opening anything.

4Create the repository and upload the project

cd %USERPROFILE%\projects\my-site
git init
git add .
git commit -m "first version"
git branch -M main
gh repo create my-site --public --source=. --push

What you see: The address https://github.com/YOUR-USER/my-site with your files.

What it is

git init enables Git in the folder, add and commit save the first version, and gh creates the repository and uploads everything. For a private repository, replace --public with --private.

Why learn it

Public: anyone can see it (required for free Pages). Private: only you and people you invite can see it. You decide for each project.

Key concepts

Repository: the project folder and its full history, stored on GitHub. Branch main: the main line of versions. Push: upload versions to GitHub.

git addpreparesgit commitsavesgit pushuploadsPagespublishes
Four commands from file to live page.

5Publish the page on GitHub Pages

gh api repos/{owner}/{repo}/pages -X POST -f "source[branch]=main" -f "source[path]=/"

What you see: In a few minutes, the page opens at https://YOUR-USER.github.io/my-site/

What it is

This command enables GitHub Pages for the repository in the current folder. You can also do it on the website: Settings → Pages → branch main → Save.

Why learn it

You get a public link to the page the agent created, without paying for hosting.

Key concepts

GitHub Pages: free hosting for pages from a repository. {owner} and {repo}: gh automatically replaces these with your username and repository name.

6Your daily routine

git status
git add .
git commit -m "what changed"
git push

What you see: git status lists what changed; after push, the change appears on GitHub and, within minutes, on the page.

What it is

Did something change? See what changed, save a version with a short sentence, and upload it. Or ask the agent: save and upload to GitHub.

Why learn it

Each commit is a restore point. If something breaks, you can recover the previous version.

Key concepts

git status: shows what changed since the last version. Commit message: a sentence that says what changed, so you can find it later.

first versioncommit 1text editcommit 2new sectioncommit 3
Each commit is a restore point. The daily routine just adds points to the timeline.

HANDS-ON / ~20 MIN

Your project on GitHub and the live page

Check each item when it actually works on your computer, not when you finish reading.

Cheat sheet for part 2

git config --global user.name "Your Name"
git config --global user.email "you@email.com"
git config --global --list
ssh-keygen -t ed25519 -C "you@email.com"
explorer %USERPROFILE%\.ssh
gh auth login
ssh -T git@github.com
cd %USERPROFILE%\projects\my-site
git init
git add .
git commit -m "first version"
git branch -M main
gh repo create my-site --public --source=. --push
gh api repos/{owner}/{repo}/pages -X POST -f "source[branch]=main" -f "source[path]=/"
git status
git add .
git commit -m "what changed"
git push

Done criteria

Connect your computer to your GitHub account with an SSH key, create a repository (public or private), and publish the page.

Review what you learned

Someone asked for your key to “set up access.” Which of the two files can you send?

View the explained answer

Only id_ed25519.pub, the public key. id_ed25519, without .pub, is the private key: anyone with that file can log in as you.

Complete module