Git: Save the History of Your Work

Linux
Git
version control
command line
Create a local Git repository and practise a small, reviewable commit cycle.

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 --oneline

Repeat 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 --staged

Use 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.

  1. Ask whether another person needs the file to reproduce the project.
  2. Use git diff --staged before committing and git check-ignore -v path/to/file to explain an ignored file.
  3. 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

Review and reflect

What is the difference between saving a file and committing it? At what point has Git recorded a recoverable checkpoint?