Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

GIT
Git & GitHub
0/10 completed
Beginner
What is version control?Your first commitsBranchesGitHub and remotes
Intermediate
Merging and conflictsUndoing changesPull requests and code reviewRebasing
Advanced
Git internals
Pro
Git workflows for teams
Tracks / Git & GitHub / Beginner

GitHub and remotes

So far, everything has lived on your computer. A remote is a copy of your repository hosted somewhere else, usually GitHub, GitLab or Bitbucket. Remotes let you back up your work, share it, and collaborate.

The in-browser simulator has no network, so this lesson uses real commands to run in your own terminal.

The big picture

   Your laptop                        GitHub                     Teammate's laptop
 ┌─────────────┐   git push    ┌──────────────┐   git pull    ┌─────────────┐
 │ local repo  │ ────────────▶ │ origin (repo)│ ────────────▶ │ local repo  │
 │             │ ◀──────────── │              │ ◀──────────── │             │
 └─────────────┘   git pull    └──────────────┘   git push    └─────────────┘
  • origin is the conventional name for your main remote.
  • git push uploads your commits.
  • git fetch downloads new commits without changing your files.
  • git pull = fetch + merge (or rebase) into your current branch.

Set up authentication (once)

GitHub no longer accepts account passwords for Git. Use either:

Option A: SSH keys (recommended)

bash
ssh-keygen -t ed25519 -C "you@example.com"     # press Enter to accept the defaults
cat ~/.ssh/id_ed25519.pub                       # copy this public key
# GitHub → Settings → SSH and GPG keys → New SSH key → paste
ssh -T git@github.com                           # test it: "Hi username! You've successfully authenticated"

Option B: HTTPS with the GitHub CLI

bash
gh auth login

Push an existing project to GitHub

  1. On GitHub, click New repository and give it a name. Don't add a README if you already have one locally.
  2. Connect and push:
bash
git remote add origin git@github.com:your-username/recipe-book.git
git branch -M main
git push -u origin main

-u (--set-upstream) links your local main to origin/main, so from then on you can just type git push and git pull.

bash
git remote -v          # list remotes and their URLs

Clone an existing repository

bash
git clone git@github.com:facebook/react.git
cd react
git log --oneline -5

Cloning downloads the entire history. The remote is automatically named origin.

Daily collaboration loop

bash
git switch main
git pull                          # 1. get the latest changes
git switch -c feature/search      # 2. branch off
# ... edit, add, commit ...
git push -u origin feature/search # 3. publish your branch
# 4. open a Pull Request on GitHub (next lessons)

Remote-tracking branches

After a fetch, Git keeps read-only copies of the remote's branches, like origin/main:

bash
git fetch
git status                 # "Your branch is behind 'origin/main' by 3 commits"
git log --oneline main..origin/main   # what's new on the remote
git branch -a              # list local and remote branches

When a push is rejected

! [rejected]        main -> main (fetch first)
error: failed to push some refs

Someone pushed before you, so your history is missing their commits. Fix it by integrating their work first:

bash
git pull --rebase    # replay your commits on top of theirs (cleaner history)
git push

🚫 Never git push --force on a shared branch like main. It overwrites teammates' work. If you must force-push your own feature branch after a rebase, use git push --force-with-lease, which refuses if someone else has pushed in the meantime.

Forks: contributing to other people's projects

You can't push to repositories you don't own. Instead:

  1. Fork the repo on GitHub (this creates your own copy).
  2. Clone your fork, branch, commit, and push to your fork.
  3. Open a Pull Request from your fork to the original ("upstream") repository.
bash
git remote add upstream git@github.com:original-owner/project.git
git fetch upstream
git rebase upstream/main     # keep your fork up to date

README and GitHub profile

Every repository should have a README.md explaining what the project is, how to run it, and how to contribute. GitHub renders it on the repo's home page. Your GitHub profile, with good READMEs and green contribution squares, is a real part of a developer portfolio.

Practice (real terminal)

  1. Create a free GitHub account if you don't have one, and set up SSH.
  2. Create a local repo with a README.md, commit it, and push it to a new GitHub repository.
  3. Edit the README on GitHub's website (pencil icon), commit there, then run git pull locally and confirm the change arrived.
✎ Check your understanding

1.What does git pull do?

2.Your push is rejected because the remote has commits you don't have. What should you do?

← Branches