W12: GitHub: Account, Connect, First Repository
Your git history is a diary kept on your desk. It works without the internet, and it is yours. But a desk can burn, a laptop can be stolen, and a friend cannot read a diary that never leaves your room. GitHub is a library across town that keeps a copy of your diary safe, and can share it with anyone you choose. This lesson gets you a library card, connects your computer to the library, and puts your notes app on the shelf.
Git and GitHub
Git runs on your computer and records history (W11). GitHub is a website that stores git repositories online. Three new lessons in this school walk through every click; this one strings them together for your Pi Workbench project:
- T41: Your GitHub Account: sign up, choose a username, turn on two-factor.
- T42: Connect Your Computer to GitHub: the
ghtool and your name in git. - T43: Your First Repository:
.gitignorefirst, one command to publish, secrets kept out.
Step 1: An Account
Follow T41. Two things matter most:
- A username you will be happy with in five years. It appears in every link to your work.
- Two-factor authentication. Turn it on now. Your account will hold your code; protect it like your email.
The free plan is enough for everything in this course, including private repositories.
Step 2: Connect This Computer
GitHub has to know that your computer is allowed to push to your account. Follow T42's recommended path. In short:
gh auth login # GitHub.com, HTTPS, Yes, Login with a web browser
gh auth status # check: "Logged in to github.com account ..."
gh opens your browser, you sign in and paste a one-time code. The key is stored in your computer's keychain, never in your project. You type your password only into GitHub's own page, never into a chat with Pi.
Step 3: Publish Your Project
Your notes project is already a git repository with commits. One command creates the repository on GitHub, connects it, and pushes everything:
gh repo create notes --private --source=. --push
notesis the name on GitHub.--privatemeans only you (and people you invite) can see it.--publicmeans everyone in the world can.--source=.uses the repository in this folder. Run it from the project folder.--pushsends your commits up straight away.
Open it in the browser with gh repo view --web. You will see your files, and in the commit history, each verified request with its task number, signed by "Pi Workbench".
Public or Private?
| Private | Public | |
|---|---|---|
| Who can see the code | You and people you invite | Everyone |
| Good for | Personal apps, anything unfinished | Sharing, portfolios, open source |
| Free GitHub Pages | Not on the free plan | Yes (W14) |
| Releases (downloads) | Need a GitHub login | Anyone can download (W15) |
Start private. Making a repository public later is one setting. Making a public one private again does not un-publish what people already copied.
Before anything goes public, read T43's "Keeping Secrets Out". The rule is simple: no passwords, keys or personal data in any file, ever, because git remembers old versions too. Your data.sqlite3 is already in .gitignore, so your notes stay on your computer.
The Daily Loop
The harness commits verified work on your computer. It never pushes. Sending your history to GitHub is always your decision:
git push
A good habit: push at the end of each working session. Then GitHub always has a copy of today's work. If your laptop dies, gh repo clone notes on a new computer brings everything back, minus the data file (which you back up separately, see W08).
Pi Workbench will do this step for you soon: a recipe that creates the repository and pushes, asking for your yes before anything leaves your computer.
Working with Others
GitHub is where people work on the same project: branches, pull requests (a proposed change others can read and comment on before it joins main), and reviews. T20: GitHub & Collaboration teaches that flow. You will not need it alone, but the moment a friend wants to help with your app, it is the way.
The same applies to Pi Workbench itself: it is on GitHub too (KakkoiDev/pi-local-harness). If something in it does not work for you, opening an issue there is how you tell the people who build it.
When Push Fails
"Permission denied" or "Authentication failed" almost always means step 2 did not finish. Run gh auth status, and if it is not logged in, run gh auth login again. T42's last section lists the other causes.
This Week's Exercise
- Make your GitHub account with two-factor (T41).
- Run
gh auth login, thengh auth status(T42). - Publish your notes project as a private repository with
gh repo create. - Ask Pi for one small change. When it is verified, run
git pushand find the new commit on GitHub.
Key Takeaways
- Git keeps history on your computer; GitHub keeps a copy online and shares it
- Make an account with two-factor (T41), connect with gh auth login (T42), publish with gh repo create (T43)
- Start private; public means everyone, forever, so keep secrets out of every file
- The harness commits but never pushes: git push is always your decision
- Pull requests are how people work together on a project (T20)