Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
General Development Skills  ›  Lesson

Git — Snapshots You Can Return To

Git - Version Control 13 minGit records your project as a chain of commits, and branches let you try changes safely before merging them back.

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 line

The 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-loans

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

Adding loans to ReadingRoomStep 1 of 5
  1. 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.

quick drill

You edited Program.cs but have not run git add. What will git commit include from that file?

quick drill

Which command creates a new branch and switches to it?

quick drill

Why do bin/ and obj/ belong in .gitignore?

quick drill

What does a commit record?

Remember

  • Stage what you mean, commit a snapshot, branch before you experiment.
  • git status tells you where each file is: modified, staged or clean.
  • Ignore bin/ and obj/; never git add . blindly.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainA safe place to experiment

You want to add a loans endpoint to ReadingRoom without breaking the working main branch. Describe the Git commands you would use from start to merge, and explain why the bin and obj folders belong in .gitignore.