Git from the terminal: snapshots for your files
Git is like a photo album for a folder. Every time you are happy with your work, you take a photo (a commit). Later you can look back at any photo, see what changed, and go back if you made a mess.
- Before this course: Command Line 2 (course 7.11.2). You wrote scripts there. Git is how people keep every version of a script, a website or a set of notes without making copies like
final-v2-REAL.txt. git initcreates an empty repository: a hidden.gitfolder inside your project. Git's manual says runninggit initagain in an existing repository is safe; it does not overwrite what is there.- Tell Git who you are, once:
git config --global user.name "Your Name"andgit config --global user.email [email protected]. Per the Pro Git book,--globalapplies to every repository on your computer; leave it out inside one project to use a different identity there.git config --listshows your settings. - Files have states. Untracked: Git sees the file but does not keep it yet. Modified: a tracked file changed since the last commit. Staged: you marked the change with
git addso it goes into the next commit. git addmeans "add exactly this content to the next commit". If you edit the file again aftergit add, you must rungit addagain.git commit -m "message"saves the snapshot.git log --onelinelists snapshots, newest first.git status --shortcodes:??untracked,Aadded (staged),Mmodified. The left column is the staging area, the right column is your working folder.- A
.gitignorefile lists patterns Git should not track, such as.logor.env. Set it up early so you do not commit files you never wanted to share. - Git's first branch is called
masterunless your settings say otherwise; from Git 2.28 you can choose another name withgit config --global init.defaultBranch main. Many tools now usemain. Both work the same. - Never commit passwords, API keys or tokens. GitHub's guidance: if a secret was committed, revoke or rotate it first; removing it from history is not enough, because copies may exist in clones and forks.
| OS difference | Mac | Linux | Windows |
|---|---|---|---|
| Is Git already there? | Check; if missing, install it (for example with Homebrew, Lesson 3) | Often; if not, install it with the package manager (Lesson 3) | Usually not; git-scm.com lists winget install --id Git.Git -e --source winget (Lesson 3) |
| Check | git --version | git --version | git --version |
- Run
git --version. If you see a version number, Git is ready. If not, come back after Lesson 3. - Set your name and email once with the two
git config --globalcommands above. Check withgit config --list. - Make a practice project:
mkdir notes-projectthencd notes-projectthengit init. - Create a file:
echo "Shopping list" > notes.txt. Rungit status --short: you see?? notes.txt(untracked). - Stage and commit:
git add notes.txtthengit commit -m "Add notes file". - Change it:
echo "apple" >> notes.txt, thengit add notes.txtandgit commit -m "Add apple". Rungit log --oneline: two snapshots. - Make a
.gitignore:echo ".log" > .gitignorethenecho ".env" >> .gitignore. Createdebug.logandsecrets.env. Rungit status --short: only.gitignoreshows up, the other two are hidden from Git. Commit.gitignore. - Check:
git log --onelineshows three commits, andgit statussays the working tree is clean.
Videos by other creators on YouTube, for reference. They are not made by or affiliated with The Future Market.
Read the video script
[Host] "Git is a photo album for a folder. Each photo is called a commit."
[Text on screen: git init | git add | git commit -m] "Start the album with git init. Choose what goes in the next photo with git add. Take the photo with git commit."
[Screen: git status --short showing ?? and M] "Two question marks means Git is not tracking the file yet. M means modified."
[Text on screen: .gitignore: .log .env] "A gitignore file keeps logs and secret files out of the album."
[Host] "Never commit a password. If you ever do, change the password first."
In a new practice folder, make a Git repository with three files and at least four commits with clear messages (for example "Add budget table", not "stuff"). Add a .gitignore that hides .log and .env files and prove it works with git status --short. Write down what ??, A and M mean.
ClaudeStuck? Copy a ready-made prompt for Claude
Copy this, open Claude, paste it, and Claude will walk you through the lesson step by step.
For a grown-up: Claude is for adults (18+). Copy this, paste it into Claude, and use the answer to explain the lesson to your child.
I'm learning "Automation in the Terminal: Git, package managers and scheduled jobs" on The Future Market. Lesson 1: "Git from the terminal: snapshots for your files". What the lesson teaches: - Before this course: Command Line 2 (course 7.11.2). You wrote scripts there. Git is how people keep every version of a script, a website or a set of notes without making copies like final-v2-REAL.txt. - git init creates an empty repository: a hidden .git folder inside your project. Git's manual says running git init again in an existing repository is safe; it does not overwrite what is there. - Tell Git who you are, once: git config --global user.name "Your Name" and git config --global user.email [email protected]. Per the Pro Git book, --global applies to every repository on your computer; leave it out inside one project to use a different identity there. git config --list shows your settings. - Files have states. Untracked: Git sees the file but does not keep it yet. Modified: a tracked file changed since the last commit. Staged: you marked the change with git add so it goes into the next commit. - git add means "add exactly this content to the next commit". If you edit the file again after git add, you must run git add again. - git commit -m "message" saves the snapshot. git log --oneline lists snapshots, newest first. - git status --short codes: ?? untracked, A added (staged), M modified. The left column is the staging area, the right column is your working folder. The exercise I'm working on: In a new practice folder, make a Git repository with three files and at least four commits with clear messages (for example "Add budget table", not "stuff"). Add a .gitignore that hides .log and .env files and prove it works with git status --short. Write down what ??, A and M mean. I'm stuck. Please: 1. Explain the main idea in plain, simple words with one everyday example. 2. Walk me through the exercise one small step at a time. Ask me what I've done so far before giving the next step. 3. Don't just give me the final answer. Help me do it myself, and check my work when I share it.
I'm a parent helping my child (about 8 years old) with a lesson called "Git from the terminal: snapshots for your files" from the course "Automation in the Terminal: Git, package managers and scheduled jobs". Here's what the lesson says: Git is like a photo album for a folder. Every time you are happy with your work, you take a photo (a commit). Later you can look back at any photo, see what changed, and go back if you made a mess. The activity: In a new practice folder, make a Git repository with three files and at least four commits with clear messages (for example "Add budget table", not "stuff"). Add a .gitignore that hides .log and .env files and prove it works with git status --short. Write down what ??, A and M mean. Please explain this so an 8-year-old understands: short sentences, a fun everyday example, and no hard words. Then give me 3 simple questions I can ask my child to check they understood, and a way to do the activity together, one tiny step at a time.
Sources
- Pro Git book, First-Time Git Setup: git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
- Pro Git book, Recording Changes to the Repository: git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
- Git manual, git-init: git-scm.com/docs/git-init
- GitHub Docs, Removing sensitive data from a repository: docs.github.com/en/authentication/keeping-your-account-and-data-secure
Git: compare, undo, branch and share
This lesson is part of full access: every course and every level for one payment.
Package managers: Homebrew, winget and apt
This lesson is part of full access: every course and every level for one payment.
SSH basics: keys and remote computers
This lesson is part of full access: every course and every level for one payment.
Scheduled jobs: cron, launchd and Task Scheduler
This lesson is part of full access: every course and every level for one payment.
Safe automation habits
This lesson is part of full access: every course and every level for one payment.
Build an automated backup job
This lesson is part of full access: every course and every level for one payment.
Final project
This lesson is part of full access: every course and every level for one payment.
Quiz
What does
git adddo?It stages the current content of a file so it goes into the next commit.
What is the difference between
git diffandgit diff --staged?git diffshows unstaged changes;--stagedshows what will go into the next commit.What should you do first if you accidentally commit a password?
Change (revoke or rotate) the password; deleting it from history is not enough.
What does
git switch -c try-ideado?It creates a branch called try-idea and moves you onto it.
Name the package manager usually used on Mac, on Windows, and on Ubuntu.
Homebrew, winget and apt.
Why read a package's details before installing it?
To check it is the right tool from a publisher you trust, not a look-alike.
Which SSH key file can you share?
The public key, the file ending in
.pub.What do the five time fields of a crontab line mean?
Minute, hour, day of month, month, day of week.
Why use full paths in a scheduled job?
Scheduled jobs run with a small environment, so your usual PATH and folder may not apply.
What does
set -euo pipefaildo?It makes a Bash script stop on errors, on unset variables and when any part of a pipeline fails.
What does Apple recommend for timed jobs on a Mac?
launchd; cron still works but is deprecated.
Why should a backup job never delete old backups by itself?
A wrong path or bug could destroy data; deleting stays a manual decision.
Final exam
This lesson is part of full access: every course and every level for one payment.
Certificate
This lesson is part of full access: every course and every level for one payment.