Git fundamentals: commits, history, and branches · Lesson 5 of 5

Lesson 5: Put it together — a tiny workflow

Lesson objectives:

  • Combine init, commit, branch, and recovery in a single project.
  • Follow a safe order of operations.
  • Explain what to do when something goes wrong.

Prerequisites: Lessons 01-04 (commits, history and recovery, branches and merging) | Previous << 04 | Next: course complete

A day in the life

You now have the pieces. This lesson shows a complete workflow you can use for any small project: a short story, a set of notes, a design file, a recipe collection, or early code.

The workflow:

  1. Create a folder and run git init.
  2. Make your first commit on main.
  3. Start a branch when you want to experiment.
  4. Switch back to main when you need the stable version.
  5. Merge the experiment when it works.
  6. Use git log and git restore if you need to recover something.

Worked example (follow along)

Create a new folder for a tiny project.

Your turn (faded example)

Here is the workflow with two blanks. Fill them in.

Answer:

Common mistake breakdown

Mistake: Forgetting to commit before switching branches. If you have uncommitted changes, git switch may refuse to move or may carry changes you did not expect. Fix: commit your work first, or run git status to see what Git is about to do.

Summary + what's next

You can now initialize a repository, commit your work, branch, and recover a previous version of a file — all in your own terminal. That is the heart of Git.

The next step is to use it on a real project. Pick one folder you edit often and run git init there. Make your first commit today.

Exercises

01

Create a brand new project folder somewhere on your computer. Run git init, make one commit, and then run git log --oneline.

Level 1 (warm-up)
Done criteria · checked locally
02

Do the full workflow from this lesson: init, first commit, branch, edit on the branch, merge back, and then recover the original file from the first commit.

Level 2 (advanced)
Done criteria · checked locally