Session 13: Coach notes
Goal of this session
At the end of this session a ninja can:
- Create a GitHub account and log in.
- Create a new repository on GitHub.
- Link a local project to GitHub with
git remote add origin. - Push code to GitHub with
git push -u origin master(and afterwardsgit push). - Clone an existing GitHub repo to the laptop with
git clone. - Fetch changes with
git pull.
What is not expected: pull requests, forks, GitHub Actions, issues. Those come in sessions 14 to 15.
Preparation (30 min before the session)
- WiFi check. This session is the first one that needs internet. Test the connection at the dojo location. At least 10 laptops on WiFi at the same time. If the connection is slow, let ninjas work in groups of 2 to 3 with one GitHub account.
- GitHub account ready. Create a test account yourself if you don’t have one yet, or use your existing one. You must be able to demo.
- Email access. Check whether ninjas can get at their email. GitHub asks for email verification. If a ninja has no access to email: verification can wait. They can do the rest of the session just fine; only certain actions (such as creating an organisation) require verification.
- Explain the authentication method. GitHub no longer uses passwords in the terminal. Explain the two methods (browser-based auth and Personal Access Token; see Step 3 of the session).
Schedule (3 hours)
| Time | Activity |
|---|---|
| 0:00 to 0:10 | Recap sessions 11 to 12: commits, branches. What is there locally? |
| 0:10 to 0:25 | Projector: what is GitHub? Demo: exploring github.com |
| 0:25 to 0:50 | Creating accounts (everyone at the same time; this takes the longest) |
| 0:50 to 1:15 | Projector: new repo on GitHub, git remote add, git push |
| 1:15 to 1:30 | Break |
| 1:30 to 2:00 | On your own: pushing an existing project to GitHub |
| 2:00 to 2:20 | Projector: git clone: bringing a repo from GitHub to your laptop |
| 2:20 to 2:45 | On your own: cloning, changing, pushing, pulling |
| 2:45 to 3:00 | Showcase, cliffhanger, take-home |
Common questions
“Do I have to pay for GitHub?” No. The free subscription gives you unlimited public and private repositories. You only pay for advanced team features. For everything we do, free is enough.
“What is the difference between Public and Private?” Public = everyone on the internet can see your code. Private = only you (and the people you invite). For CoderDojo projects public is fine: you are building your portfolio. But if you ever make a project with passwords or personal data, put it on private.
“GitHub asks for a password in the terminal, but my password doesn’t work!” Since 2021 GitHub no longer accepts passwords via the terminal. You either log in via the browser (GitHub opens a window), or you use a Personal Access Token. See Step 3 of the session.
“I get ‘Permission denied’ on git push”
Usually this means: you are trying to push to a repo that isn’t yours, or your authentication has expired. Check: are you in the right folder? Is the remote correct? (git remote -v). Try logging in again.
“What if I accidentally push a password or API key?”
Stop immediately. Change the password or the key right away. Then: Google “BFG Repo-Cleaner” or “git filter-branch” to remove it from the history. But remember: if someone has already cloned your repo, they still have the password. The real solution is: never put passwords in Git. Use .gitignore and environment variables.
Hints for Stretch and Expert
Stretch: several remotes:
You can add several remotes: git remote add backup https://gitlab.com/.... Handy for extra backups. Use git remote -v to see them.
Expert: git push without -u:
The first push needs -u origin master to set the upstream branch. After that Git remembers the link and git push is enough. If you push from a branch other than master, do git push -u origin branch-name the first time.
Cliffhanger script
“Your code is online. But what if you work together with someone else? How do you make sure your code doesn’t clash with someone else’s? How do you ask politely: ‘May this change go into the main project?’ Next time: pull requests, the front door of every professional software project.”
Practical pitfalls
Creating a GitHub account takes longer than you think. Email verification, choosing a username, clicking through the welcome flow: count on 10 to 15 minutes per ninja. Let them do this at the same time and walk around for help.
Typos in usernames.
git remote add origin https://github.com/JOUW_USERNAME/repo.git: one typo and the remote doesn’t work. Check URLs twice before they push.Case sensitivity.
github.com/JOUW_USERNAMEis not the same asgithub.com/jouw_username. GitHub usernames are case-insensitive, but it is a good habit to copy exactly what GitHub shows.The first push can be slow. Depending on the internet connection the first push can take a few seconds up to a minute. Warn ninjas that they shouldn’t panic if the terminal seems to “hang” for a moment.