Quiz
Warm-up from lesson 1-1. Which statement about Git and GitHub is correct?
Remotes
A remote is another copy of your repository living somewhere else, almost always on a server such as GitHub. The server copy is the meeting point: you send your commits up to it, teammates send theirs, everyone downloads everyone else's.
Getting a project from GitHub takes one command. Every repository page on GitHub shows a URL, and:
$ git clone https://github.com/octocat/recipe-book.git Cloning into 'recipe-book'... remote: Enumerating objects: 128, done. Receiving objects: 100% (128/128), done.
git clone creates a folder, downloads the repository into it, and wires the folder back to the URL it came from. And because a Git repository is its history, you receive every commit ever made, the full chain from lesson 1-2, not just the latest files. You can run git log, git diff, and git switch on an airplane, the whole database is local.
origin, the default nickname
Typing the full URL constantly would be miserable, so Git gives remotes short names. When you clone, the source URL is automatically nicknamed origin:
$ git remote -v origin https://github.com/octocat/recipe-book.git (fetch) origin https://github.com/octocat/recipe-book.git (push)
That's all origin is: a bookmark meaning "the server this project came from." There is nothing magical about the name, but since every clone gets it automatically, it's the word you'll see in every push and pull for the rest of your career.
Starting a project the other direction (local first) works too: create an empty repository on GitHub, then connect it yourself with git remote add origin <url>.
Proving who you are
Reading a public repository needs no account — git clone on a public URL just works, which is why you could grab any open-source project today. Writing is different: git push (next lesson) changes the project on the server, so the server must verify you're allowed to. Without that check, anyone could rewrite anyone's code. GitHub accepts two forms of ID:
- HTTPS + personal access token. GitHub stopped accepting account passwords for Git operations in 2021 (passwords leak and can't be scoped). You generate a token in GitHub's settings — a long random string acting as a limited-purpose password — and paste it when Git prompts. A credential helper (enabled by default on macOS and Windows) remembers it after the first time.
- SSH keys. You generate a key pair once (
ssh-keygen), upload the public half to GitHub, and keep the private half on your machine. Clones use thegit@github.com:...URL form, and pushes authenticate silently with no prompts.
Both are fine; SSH is the usual choice on a computer you own because it never prompts again. Either way this is a one-time setup toll everyone pays — budget ten minutes with GitHub's current docs the first time a push asks you to prove yourself.
Quiz
After git clone finishes, which of these do you have on your machine?
Quiz
git clone of a public repository works with no account, but git push demands authentication. Why the difference?
Problem
A teammate sends you the URL of a GitHub repository. Which command downloads the whole repository, history included, onto your machine?