Git and GitHub basics
You'll learn to save versions of your project with Git, read git status, and put your code on GitHub.
Watch & read
Start with the required ones. The others are there when you need them.
Explanation
You change your code, it breaks, and you cannot remember what it looked like when it worked. Or your laptop dies before submission. Git solves the first problem. GitHub solves the second.
Think of Git as taking photos of your project folder. Each photo is a commit: a saved version with a short note saying what changed. You can look back at any old photo. A folder that Git is watching is called a repository (repo for short). GitHub is a website that keeps a copy of your repo online, like Google Drive for code.
Taking a photo has two steps. First you choose which changes go in the photo, called staging, with
git add. Then you take it with git commit.
git init start watching this folder (once)git status what changed? what is staged?git add hello.js put this change in the next photogit commit -m "Add greeting" take the photo, with a messagegit log --oneline list the photos so far
To put your repo on GitHub, make an empty repo on github.com, then copy the two or three commands it shows
you (git remote add origin … and git push -u origin main). After that, git push sends your new
commits up.
A good commit message says what the change does, in a few words: Add login button,
Fix total when cart is empty. A message like update or asdf tells future you nothing.
People often edit a file and run git commit straight away. Git replies "no changes added to commit".
You forgot git add. Git only saves what you staged, so you can choose what goes in each photo.
Run git status all the time. Read it top to bottom: "Changes to be committed" (green) are staged and
will be in the next commit. "Changes not staged" (red) are edited but not added yet. "Untracked files" are
new files Git is not watching yet.
Code tour
Click a line number with a ring to read the note for that line.
Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3You edited
hello.jsand rangit commit -m "Fix name". Git says no changes added to commit. Why? - 2 / 3In
git status, a file is under "Changes not staged for commit". What does that mean? - 3 / 3Which commit message is most useful?
Explain it back
How confident are you with Git and GitHub basics?
Done
git status is telling you, and push your work to GitHub.