Branching — Module Recap
Module 03 is complete. You can now create, switch, merge, and delete branches — the full lifecycle of a feature branch. This is the workflow pattern you will use for the rest of your development career.
What you learned
Section titled “What you learned”What branches are — A branch is a lightweight movable pointer to a commit. No code is copied. Creating a branch costs almost nothing. HEAD is a special pointer tracking your current position in the repository.
Creating and switching branches — git switch -c <name> creates a branch and switches to it in one step. Switching branches updates your working tree to reflect that branch’s state. Git will not let you switch with uncommitted changes that would be overwritten.
Merging branches — Always merge into the branch you want to update. A fast-forward merge moves the pointer forward with no merge commit (linear history). A merge commit is created when both branches have diverged. Merge conflicts occur when the same region of a file was changed on both branches — resolve by editing the conflict markers, staging, and committing.
Branch naming conventions — Use a prefix/description pattern: feature/, fix/, docs/, refactor/, chore/. Lowercase, hyphenated, specific. GitHub Flow: main is always deployable, every change goes on a short-lived branch, merged via pull request.
Deleting merged branches — git branch -d is safe (refuses to delete unmerged work). git branch -D is force delete. git branch --merged main lists what is safe to clean up. Delete the remote branch with git push origin --delete <name>.
Command reference
Section titled “Command reference”| Command | What it does |
|---|---|
git branch | List local branches (* marks current) |
git branch <name> | Create a branch at the current commit |
git switch <name> | Switch to an existing branch |
git switch -c <name> | Create and switch to a new branch |
git merge <branch> | Merge a branch into the current branch |
git merge --abort | Abort an in-progress merge and restore pre-merge state |
git branch -d <name> | Delete a merged branch (safe) |
git branch -D <name> | Force-delete a branch regardless of merge status |
git branch --merged main | List branches fully merged into main |
git branch --no-merged main | List branches with unmerged commits |
git branch -a | List local and remote branches |
git push origin --delete <name> | Delete a remote branch |
git fetch --prune | Remove stale remote-tracking references |
The standard branching workflow
Section titled “The standard branching workflow”For solo or team development:
git switch -c feature/your-feature # 1. create and switch# make changes, git add, git commit... # 2. developgit switch main # 3. return to maingit merge feature/your-feature # 4. mergegit branch -d feature/your-feature # 5. delete the branchThis five-step cycle is the foundation of every workflow covered from here forward.
What’s next — Undoing Changes
Section titled “What’s next — Undoing Changes”Module 04 covers the full range of undo operations in Git:
- Discarding changes in your working tree that you have not staged
- Unstaging files you added by mistake
- Amending the last commit — fixing the message or adding forgotten files
git revert— creating a new commit that undoes a previous commit, safely, without rewriting historygit reset— rewinding the branch pointer to an earlier commit, understanding the three modes
Every developer needs these tools eventually. Knowing which one to reach for — and why — is the difference between a quick fix and a panic.