Git branching & checkout
Git branching and checkout covers working on independent lines of commits while main stays deployable. A branch is a lightweight pointer to a commit, and HEAD marks your current position. The lessons show how to create and switch branches with git switch and git checkout -b, inspect and compare them, and rename or delete them safely. They also cover detached HEAD, pushing and tracking branches on a remote, and building one feature on its own branch from the first commit to the push.
What you'll learn
- ✓How a branch works as a lightweight pointer to a commit, with HEAD marking your position
- ✓Creating and switching branches with git switch, switch -c and checkout -b
- ✓Listing and comparing branches with git branch -a, -vv, git diff and git log
- ✓Renaming and deleting branches with -m, -d and -D, and recovering commits with git reflog
- ✓What detached HEAD means and how to keep work made in that state
- ✓Pushing, tracking and pruning branches on a remote
Why branches: isolating work without touching main
Every commit across the last three courses landed on the same branch, main, one after another. That works fine for a solo learning exercise. It breaks down the moment real work looks like this: you're halfway through a risky refactor, a critical bug report comes in, and main needs an emergency fix:…
Read the full lesson free →Curriculum
7 lessonsWhy branches: isolating work without touching main
Explains why branches isolate work from main, and how a branch is a lightweight pointer to a commit.
Creating and switching branches: branch, switch, checkout -b
Creates and switches branches with git branch, git switch, switch -c and checkout -b, and handles uncommitted changes with stash.
Inspecting and comparing branches
Lists branches with git branch -a and -vv, draws the history graph, and compares branches with diff and log.
Renaming and deleting branches safely
Renames branches with -m, deletes them with -d or -D, removes remote branches, and recovers commits through git reflog.
Detached HEAD: checking out a specific commit
Explains detached HEAD, when checking out a raw commit is safe, and how to save commits made there.
Branches and remotes together
Pushes new branches, checks out a teammate's remote branch with switch, merges in main's updates, and prunes stale references.
Putting it all together: a feature branch from start to push
Builds a discount_percentage feature on its own branch, confirms main stays untouched, and pushes the branch to the remote.