Skip to content

Branch Workflow Simulation

Medium~25 min

What you'll build

A repository where you create a feature branch, add a change on it, switch back to main, merge the branch, and delete it. The full branch lifecycle on a toy project.

Goals

  • Create and switch branches with git checkout -b
  • Make commits on a branch without affecting main
  • Merge a branch back into main with git merge
  • Delete a merged branch to keep the repo clean

Prerequisites

  • git init, add, commit (Create Repository Workflow)
  • Understanding that branches are independent lines of work

Steps

  1. 1

    Set up main with a base commit

    Create a repository and make one commit on the default main branch. This is the stable base that your feature branch will build on.

    Code
    mkdir branch-sim
    cd branch-sim
    git init
    echo "# Branch Sim" > README.md
    git add .
    git commit -m "Initial commit"

    Expected result

    A repository on main with one commit.

  2. 2

    Create and switch to a feature branch

    Run git checkout -b add-greeting to create a new branch and switch to it in one step. Commits made here will not affect main until you merge.

    Code
    git checkout -b add-greeting

    Expected result

    Git prints "Switched to a new branch 'add-greeting'".

  3. 3

    Make a commit on the feature branch

    Add a new file and commit it on the feature branch. Because you are on add-greeting, main is untouched — this is the whole point of branching.

    Code
    echo "print('hi from feature branch')" > greet.py
    git add greet.py
    git commit -m "Add greeting script on feature branch"

    Expected result

    A commit exists on add-greeting; main still has only the initial commit.

  4. 4

    Switch back to main and merge

    Run git checkout main to return to the main branch, then git merge add-greeting to bring the feature commit in. After merging, main has the same files as the branch.

    Code
    git checkout main
    git merge add-greeting

    Expected result

    main now contains greet.py; git log shows both commits.

  5. 5

    Delete the merged branch

    Run git branch -d add-greeting to delete the branch. The -d flag only deletes fully merged branches, so it is safe — no work is lost.

    Code
    git branch -d add-greeting
    git branch
    git log --oneline

    Expected result

    Only main remains; the log shows both commits on main.

Try it yourself

What you learned

You simulated the full feature-branch lifecycle — create, commit, merge, delete — which is the workflow every team uses to develop features without destabilizing the main branch.

Related Resources

Related Lessons

  • Git Branches

    Branch creation, switching, merging, and deletion covered here.

  • Git Basics

    The underlying commit and log commands used throughout.

Related Practice

Related Tools

Related Cheatsheets

Related Reference

Related Errors

Related Glossary

  • Branch

    Independent lines of work.

  • Merge

    Combining branches together.

  • Remote

    Remote repository references.

Related Glossary

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

  • Branch

    Independent lines of work.

  • Merge

    Combining branches together.

  • Remote

    Remote repository references.

Related Errors

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

← Back to topic