Skip to main content
Once a project is in version control, you need a safe way to try new ideas without destabilizing the main codebase. Branching in Git is the standard way to:
  • develop multiple features in parallel,
  • iterate on experiments, and
  • isolate bug fixes until they’re ready to land.
A branch is simply a lightweight pointer to a commit. Create a branch for each independent piece of work so you can iterate safely and merge only when ready.
Create a branch for each independent piece of work. Branches are cheap and let you iterate safely.

Inspecting branches

List branches in your repository:
Typical output when only main exists:

Creating and switching branches

Create a new branch without switching to it:
Switch to that branch:
You can create and switch in a single step:
After switching, edits affect only exploring-coloring until you merge or rebase them into main. Example branch listing after creation and checkout:

Example changes (style and gameplay)

Imagine you want to update UI colors and increase the number of lives in a browser game. Here are representative excerpts from style.css and script.js that show the changes you might make on the exploring-coloring branch. Updated CSS variables (selective excerpt from style.css):
Representative game state in script.js (cleaned and corrected):
Update the startGame function so fresh games start with five lives:
Save these files while you are on exploring-coloring and test the app. You should see the updated color scheme and five starting lives.

Staging and committing changes

Check your working tree:
Example output when two files changed:
Stage and commit your edits:
Example commit output:
If you prefer a GUI, VS Code’s Source Control view provides staging, diffing, and committing.

Useful Git commands (quick reference)

Inspecting history across branches

git log shows commits reachable from HEAD. These variations help visualize branch structure and history: Example compact output (actual hashes will differ):
The --graph and --oneline flags are especially helpful for visualizing how branches diverge and where HEAD currently points.
Before merging, ensure you don’t accidentally commit sensitive files (API keys, large binaries) and resolve any merge conflicts locally. Run your test suite or smoke tests after merging to confirm behavior.

Merging back into main

When your changes are tested and ready:
  1. Switch to main:
  2. Update main from the remote:
  3. Merge your feature branch:
  4. Resolve any conflicts, run tests, then push:
Alternatively, open a pull request in your Git hosting service (GitHub, GitLab, Bitbucket) to get peer review and automated CI checks before merging.
By using a dedicated branch like exploring-coloring, you keep your experiments isolated from main, enabling safe iteration and easier collaboration. When ready, merge via PR or locally following your team’s workflow.

Watch Video