Meet GitHub
Table of Contents
- Create a GitHub Account
- Signing In from the Terminal
- Install the GitHub CLI and Log In
- Create a Repository on GitHub
- Connect Your Project: git remote
- Upload It: git push
- Add a README
- Download It: git clone
- Public, Private, and Secrets
- Try It Yourself
1. Create a GitHub Account
Go to github.com and sign up. It's free, and the free plan includes unlimited public and private repositories.
A few choices matter more than they seem:
- Your username is public and permanent-ish. It appears in the
address of every project —
github.com/<username>/my-site— and employers will see it. Your real name, or something close to it, is a good choice. (dara-sokbeatsxX_dara_Xx.) - Use the email you set as
user.emailin chapter 2, so GitHub can connect your commits to your account. If you set a different one, add it under Settings → Emails. - Turn on two-factor authentication (2FA) under Settings → Password and authentication. GitHub requires it for anyone who contributes code, and it stops someone who guesses your password from taking over your account. An authenticator app on your phone works well.
While you're there, add a profile photo and a short bio. Your GitHub profile becomes part of your portfolio.
2. Signing In from the Terminal
When you send code to GitHub, Git has to prove it's you. You might expect to type your GitHub password — but GitHub doesn't accept account passwords for Git operations. That was turned off in 2021, because passwords are too easy to steal and reuse.
Instead, Git needs one of two things:
- a token sent over HTTPS — a long, random, revocable key, or
- an SSH key — a pair of keys stored on your computer
Both work. Creating and storing a token by hand is fiddly, so this
series uses the GitHub CLI (gh), GitHub's official terminal tool.
It logs you in through your browser and sets up Git for you in one
step.
SSH keys are the other common choice, and you'll meet them again when you work with servers. If you'd like to use them for GitHub, the official guide is under Docs → Authentication → Connecting to GitHub with SSH. Everything else in this series works the same either way.
3. Install the GitHub CLI and Log In
Install gh:
# macOS (Homebrew)
brew install gh
# Windows with Git Bash (run in PowerShell)
winget install --id GitHub.cli
On Linux and WSL, install it inside Linux — not with winget,
which would put it on the Windows side where your WSL terminal can't
use it. Recent Ubuntu versions have it as a package
(sudo apt install gh); otherwise follow the instructions for your
distribution at cli.github.com. Close and
reopen your terminal, then check:
gh --version
Now log in:
gh auth login
It asks a few questions. Use the arrow keys and Enter to choose:
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: 1A2B-3C4D
Press Enter to open https://github.com/login/device in your browser...
Copy the code, press Enter, paste the code into the page that opens,
and click Authorize. Back in the terminal:
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as dara-sok
Check it any time with:
gh auth status
That's it — from now on, git push and git pull to GitHub just work.
You don't need to use gh for anything else in this series, though
it can do a lot (you'll see a couple of shortcuts later).
4. Create a Repository on GitHub
On GitHub, click the + in the top-right corner → New repository, and fill in:
- Repository name:
my-site - Description:
My personal website, built while learning Git - Public (needed for free GitHub Pages hosting in chapter 11)
Leave everything under "Initialize this repository with" unchecked
— no README, no .gitignore, no license. You already have a project
with history; you want GitHub to start with an empty repository to push
it into. (If GitHub creates its own first commit, your two histories
won't match, and the first push gets complicated.)
Click Create repository. GitHub shows a "Quick setup" page with the repository's address. It looks like this:
https://github.com/dara-sok/my-site.git
5. Connect Your Project: git remote
Your local repository doesn't know GitHub exists yet. Tell it, from
inside my-site:
git remote add origin https://github.com/dara-sok/my-site.git
(Use your own username, of course.) This adds a remote — a named
link to another copy of the repository. origin is the name
everyone uses for "the main copy on GitHub". It's only a convention,
but you'll see it in every project and every tutorial.
Check it:
git remote -v
origin https://github.com/dara-sok/my-site.git (fetch)
origin https://github.com/dara-sok/my-site.git (push)
6. Upload It: git push
Send your commits up to GitHub:
git push -u origin main
Enumerating objects: 34, done.
Counting objects: 100% (34/34), done.
Delta compression using up to 8 threads
Compressing objects: 100% (30/30), done.
Writing objects: 100% (34/34), 3.41 KiB | 3.41 MiB/s, done.
Total 34 (delta 12), reused 0 (delta 0), pack-reused 0
To https://github.com/dara-sok/my-site.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
This means: "push my main branch to origin". The -u makes your
local main remember that it belongs with origin/main, so from now on
you can just type:
git push
Refresh the repository page on GitHub. Your files are there. Click the
commits link (with the clock icon): your entire history is
there too, with the same messages, authors, and hashes as
git log --oneline on your computer. Git didn't upload just the
files — it copied the whole repository.
7. Add a README
When someone opens your repository, GitHub shows a file called
README.md below the file list, if one exists. It's the front page of
your project. The .md means Markdown, a simple way to format
text: # for headings, - for lists, and **bold**.
Create README.md in my-site:
# my-site
My personal website, built while learning Git and GitHub.
## Pages
- `index.html` — home
- `about.html` — about me
- `contact.html` — how to reach me
Then the usual loop, plus a push:
git add README.md
git commit -m "Add README"
git push
Refresh GitHub, and your README appears on the front page of the repository. Every serious project has one — it's the first thing people read.
8. Download It: git clone
Pushing uploads a repository; cloning downloads one. Try it now, as
if you were on a different computer. Go to your home folder and clone
your repository into a new folder called my-site-laptop:
cd ~
git clone https://github.com/dara-sok/my-site.git my-site-laptop
cd my-site-laptop
git log --oneline
Everything is there: every file, every commit, every message. Cloning
also sets up origin automatically, so git push and git pull work
straight away.
You'll use cloning for:
- getting your own project onto a new computer
- downloading someone else's project to run or study it — like the source code for the Docker or NestJS tutorials on this site
- joining a team project at work, usually your first command on day one
Keep my-site-laptop — in the next chapter you'll use it to
pretend to be a second computer.
Shortcut: once you're comfortable, the GitHub CLI can create the GitHub repository, add the remote, and push in one command, from inside an existing project:
gh repo create my-site --public --source=. --remote=origin --push
9. Public, Private, and Secrets
- Public repositories can be seen by anyone on the internet. Great for portfolios, open-source projects, and learning in public.
- Private repositories are visible only to you and the people you invite. Use these for client work, or anything you're not ready to share. You can change visibility later under Settings.
Either way, never push passwords, API keys, or .env files.
Automated bots scan public GitHub repositories for leaked keys around
the clock, and a leaked cloud key can be abused within minutes. GitHub
may block a push that contains something that looks like a known key —
but don't rely on that. Keep secrets in .gitignored files, and if one
ever does get pushed, revoke or change it immediately; deleting it
in a new commit doesn't remove it from history.
10. Try It Yourself
- Create your GitHub account and turn on two-factor authentication.
- Install
ghand rungh auth login. Thengh auth status. - Create an empty
my-siterepository on GitHub, add it asorigin, andgit push -u origin main. - Explore your repository on GitHub. Open the commits list and
compare it with
git log --oneline. Click a commit to see its diff. Openindex.htmland click Blame. - Add a README, push it, and see it on the front page.
- Clone it into
~/my-site-laptopand check the history is complete.
Your project now lives in two places. Next, let's keep them in sync.
Buy Me a Coffee
Found this tutorial helpful? Consider buying me a coffee to support more free content!