Git — Snapshots You Can Return To
You change three files in ReadingRoom, and suddenly nothing starts. Which change broke it? Without version control you guess. With Git you ask for the difference against the last working version and see it line by line.
The rule
Stage what you mean, commit a snapshot, branch before you experiment.
Git keeps your project's history as a chain of commits. Each commit is a snapshot of the tracked files plus a message saying why it changed.
git init # start tracking this folder
git status # what changed since the last commit?
git add Program.cs # stage: choose what goes in the next commit
git commit -m "Add GET /books" # record the snapshot
git log --oneline # list the history
git diff # show unstaged changes line by lineThe staging area sits between your files and the history, so one commit can hold exactly the change you intended and nothing else.
A branch is a movable name pointing at a commit. main holds the working version. To try something, make a new branch; your commits move only that branch. When it works, merge it back.
git switch -c add-loans # create a branch and move onto it
# ...edit, add, commit...
git switch main
git merge add-loansA .gitignore file lists what Git should never track. For .NET that is the bin/ and obj/ build folders and local secrets. dotnet new gitignore writes a ready-made one.
The shortcut
Before any Git command, say where you are in the loop: change → stage → commit. git status always tells you which step each file is at: untracked, modified, staged, or clean.
Branch first
git switch -c add-loans. Main keeps the working API while you experiment.
The trap: git add . without looking. It stages everything, including files you never meant to share. Check git status first.
Drills
Answer fast — trust the rule.
You edited Program.cs but have not run git add. What will git commit include from that file?
Which command creates a new branch and switches to it?
Why do bin/ and obj/ belong in .gitignore?
What does a commit record?
Remember
- Stage what you mean, commit a snapshot, branch before you experiment.
git statustells you where each file is: modified, staged or clean.- Ignore
bin/andobj/; nevergit add .blindly.
