Git: Save the History of Your Work
Learning goals
- I will be able to explain repository, working tree, stage, commit, and history.
- I will be able to create a repository and make small commits with useful messages.
- I will be able to inspect changes before saving or sharing them.
This is important because it enables me to experiment, explain what changed, and recover earlier work without creating files named final-final-really-final.
Your first repository
Create a teacher-approved project folder inside your home directory. Configure Git with the classroom identity supplied by your teacher. Do not publish a personal email address.
mkdir -p ~/linux-labs/my-site
cd ~/linux-labs/my-site
git init
printf "# My Technology Site\n" > README.md
git status
git add README.md
git diff --staged
git commit -m "Add project README"
git log --onelineRepeat the cycle after making one small change: edit, git status, review, stage, review the staged change, commit, and inspect the history.
Use Git with notebooks and websites
Commit source files that another person needs to reproduce the work: .qmd, Markdown, configuration, code, small approved datasets, notebooks, and licensed assets. Do not commit Quarto’s generated _site or .quarto folders for the classroom starter. Do not commit virtual environments, passwords, tokens, class codes, private student evidence, or restricted teacher resources.
Before every commit:
git status
git diff
git diff --stagedUse git add with the intended paths, then inspect the staged diff. A useful commit contains one understandable change and a message that explains it.
The problem
git status shows an unfamiliar generated file and a notebook containing output you did not intend to share.
The challenge: decide what is source, what is generated, and what is private. Update .gitignore only for a repeatable file pattern, not to hide a mistake after it has been committed.
- Ask whether another person needs the file to reproduce the project.
- Use
git diff --stagedbefore committing andgit check-ignore -v path/to/fileto explain an ignored file. - If a secret was committed, stop and tell the teacher; deleting the current file does not remove it from earlier history.
Common issues
| Problem | Check |
|---|---|
| Git asks for identity | Use the teacher-approved classroom identity. Do not invent or publish a private email address. |
| Everything is in one large commit | Unstage safely with git restore --staged <path>, then stage one coherent change. |
| Line endings appear changed | Confirm the actual content and classroom Git configuration before committing a mass rewrite. |
| Merge conflict markers appear | Do not delete them blindly. Compare both versions, keep the correct combined content, test, then stage the resolution. |
Evidence
Submit the repository path, a screenshot of git log --oneline, and a six-step explanation of your commit cycle. Explain why a commit message should describe the change.
Extend your learning
- Read Getting started with Git.
- Use
git diffto compare an uncommitted change with the last commit. - Continue to Build a Website with Quarto and use the same small commit cycle.
Review and reflect
What is the difference between saving a file and committing it? At what point has Git recorded a recoverable checkpoint?