Module 4: Branches and Merging
08. Mini-project: Multi-Branch Workflow
Capsule overview
In this capsule you'll consolidate everything you learned in Module 4 by simulating a complete professional workflow with multiple branches. You'll develop 2 features at the same time, create an urgent hotfix, resolve conflicts, and apply the Feature Branch Workflow.
This project will get you ready to work with Git on real teams.
Goal of the mini-project
Simulate a real week of development:
- ✅ Work on several features at the same time
- ✅ Handle an urgent hotfix that interrupts your work
- ✅ Resolve merge conflicts
- ✅ Apply the Feature Branch Workflow
- ✅ Clean up branches after merging
- ✅ Keep the history clean
Estimated time: 60-75 minutes
Project context
The scenario:
You're a developer at an e-commerce startup. This week you have to:
- Implement an authentication system (a big feature)
- Add search filters (a medium feature)
- Fix a critical bug in production (an urgent hotfix)
The repo: an e-commerce app with a basic structure.
Phase 1: Project setup (10 min)
Step 1: Create the base repo
# 1. Create the directory
mkdir ecommerce-project
cd ecommerce-project
git init
# 2. Configure the user
git config user.name "Your Name"
git config user.email "you@email.com"
# 3. Create the initial structure
mkdir -p src/{auth,products,search}
touch src/auth/auth.js
touch src/products/products.js
touch src/search/search.js
touch README.md
# 4. Initial content
cat > README.md << 'EOF'
# E-commerce Project
## Features
- Product catalog
- User authentication
- Search functionality
EOF
cat > src/products/products.js << 'EOF'
// Products module
function getProducts() {
return [
{ id: 1, name: "Laptop", price: 1200 },
{ id: 2, name: "Mouse", price: 25 }
];
}
module.exports = { getProducts };
EOF
# 5. Initial commit
git add .
git commit -m "chore: Initial project structure"
# 6. Check the state
git log --oneline
Step 2: Set up some useful aliases
git config alias.tree "log --oneline --graph --all --decorate"
git config alias.st "status -sb"
git config alias.sw "switch"
Phase 2: Feature 1 - Authentication System (20 min)
Step 1: Create the feature branch
# From main
git switch -c feature/user-authentication
git branch
# * feature/user-authentication
# main
Step 2: Implement login
cat > src/auth/auth.js << 'EOF'
// Authentication module
const users = [
{ id: 1, username: "admin", password: "admin123" },
{ id: 2, username: "user", password: "user123" }
];
function login(username, password) {
const user = users.find(u =>
u.username === username && u.password === password
);
if (user) {
return { success: true, userId: user.id };
}
return { success: false, error: "Invalid credentials" };
}
module.exports = { login };
EOF
git add src/auth/auth.js
git commit -m "feat(auth): Add login functionality"
Step 3: Implement registration
cat > src/auth/register.js << 'EOF'
// User registration
function register(username, password, email) {
// Validation
if (!username || !password || !email) {
return { success: false, error: "Missing fields" };
}
if (password.length < 6) {
return { success: false, error: "Password too short" };
}
// Save user (mock)
return { success: true, userId: Date.now() };
}
module.exports = { register };
EOF
git add src/auth/register.js
git commit -m "feat(auth): Add user registration"
Step 4: Update the README
cat >> README.md << 'EOF'
## Authentication
- User login
- User registration
- Password validation
EOF
git add README.md
git commit -m "docs: Add authentication documentation"
Step 5: Check your progress
git tree
Output:
* f3d7a2c (HEAD -> feature/user-authentication) docs: Add auth docs
* e2c6b1a feat(auth): Add user registration
* d1b5a0c feat(auth): Add login functionality
* c0a4f9e (main) chore: Initial project structure
Phase 3: Feature 2 - Search Filters (15 min)
Step 1: Go back to main and create a new branch
# Back to main (the auth feature is unfinished)
git switch main
# Create the branch for search
git switch -c feature/search-filters
Step 2: Implement the filters
cat > src/search/search.js << 'EOF'
// Search functionality
function searchProducts(products, query) {
if (!query) return products;
return products.filter(product =>
product.name.toLowerCase().includes(query.toLowerCase())
);
}
function filterByPrice(products, minPrice, maxPrice) {
return products.filter(product =>
product.price >= minPrice && product.price <= maxPrice
);
}
module.exports = { searchProducts, filterByPrice };
EOF
git add src/search/search.js
git commit -m "feat(search): Add search and price filters"
Step 3: Look at your active branches
git branch
Output:
feature/user-authentication
* feature/search-filters
main
You have 2 features in progress at the same time.
Phase 4: Urgent Hotfix (10 min)
Scenario: Critical bug in production
Slack notification: "🚨 URGENT: Products.js is crashing in production"
Step 1: Save your current work (stash)
# You're on feature/search-filters with work in progress
echo "// WIP: Adding category filter" >> src/search/search.js
git stash push -m "WIP: Category filter implementation"
Step 2: Create the hotfix from main
git switch main
git switch -c hotfix/product-crash
Step 3: Fix the bug
cat > src/products/products.js << 'EOF'
// Products module
function getProducts() {
// FIX: Ensure array is never null
const products = [
{ id: 1, name: "Laptop", price: 1200 },
{ id: 2, name: "Mouse", price: 25 },
{ id: 3, name: "Keyboard", price: 75 }
];
// Add safety check
return Array.isArray(products) ? products : [];
}
module.exports = { getProducts };
EOF
git add src/products/products.js
git commit -m "hotfix: Add null check to prevent crash"
Step 4: Merge the hotfix into main
git switch main
git merge --no-ff hotfix/product-crash -m "Merge hotfix: product crash"
# Verify
git tree
Output:
* g5h8i4j (HEAD -> main) Merge hotfix: product crash
|\
| * f4g7h3i (hotfix/product-crash) hotfix: Add null check
|/
* c0a4f9e chore: Initial project structure
Step 5: Clean up the hotfix branch
git branch -d hotfix/product-crash
Step 6: Get back to the search work
git switch feature/search-filters
git stash pop
# Keep working
Phase 5: Merging Features with Conflicts (20 min)
Step 1: Finish the search feature
# On feature/search-filters
echo "// Category filter complete" >> src/search/search.js
git add .
git commit -m "feat(search): Complete category filter"
# Update the README
cat >> README.md << 'EOF'
## Search
- Product search by name
- Price range filter
- Category filter
EOF
git add README.md
git commit -m "docs: Add search documentation"
Step 2: Merge search into main
git switch main
git merge --no-ff feature/search-filters
# Look at the history
git tree
Output:
* h6i9j5k (HEAD -> main) Merge feature/search-filters
|\
| * g5h8i4j docs: Add search documentation
| * f4g7h3i feat(search): Complete category filter
| * e3f6g2h feat(search): Add search and price filters
|/
* c0a4f9e Initial commit
Step 3: Clean up the search branch
git branch -d feature/search-filters
Step 4: Update the auth feature with main
# Switch to the auth branch
git switch feature/user-authentication
# See the difference against main
git log feature/user-authentication..main --oneline
# Merge main into the feature (to bring it up to date)
git merge main
A likely conflict in README.md:
<<<<<<< HEAD
## Authentication
- User login
- User registration
=======
## Search
- Product search by name
- Price range filter
>>>>>>> main
Step 5: Resolve the conflict
Edit README.md:
# E-commerce Project
## Features
- Product catalog
- User authentication
- Search functionality
## Authentication
- User login
- User registration
- Password validation
## Search
- Product search by name
- Price range filter
- Category filter
git add README.md
git commit -m "merge: Resolve conflict in README"
Step 6: Finish and merge auth
# Add logout
cat > src/auth/logout.js << 'EOF'
// Logout functionality
function logout(userId) {
// Clear session (mock)
return { success: true };
}
module.exports = { logout };
EOF
git add src/auth/logout.js
git commit -m "feat(auth): Add logout functionality"
# Merge into main
git switch main
git merge --no-ff feature/user-authentication
# Clean up
git branch -d feature/user-authentication
Phase 6: Final Check (5 min)
Step 1: Look at the full history
git tree
It should show:
- Main with 2 feature merges
- 1 hotfix merge
- Clean history with descriptive messages
Step 2: Look at the final structure
tree -L 2
Output:
.
├── README.md
└── src
├── auth
│ ├── auth.js
│ ├── register.js
│ └── logout.js
├── products
│ └── products.js
└── search
└── search.js
Step 3: Confirm no branches are left
git branch
Output:
* main
Only main — the branches are cleaned up.
Success criteria
You've completed this successfully if:
- You worked on 2 features at the same time
- You created a hotfix that interrupted your work
- You used stash to save work temporarily
- You resolved the conflict in README.md
- You merged with --no-ff to get merge commits
- You deleted the branches after merging
- Your history has descriptive messages
- Main has every feature integrated
Project troubleshooting
Problem 1: I forgot which branch I'm on
git st # Shows the current branch
git branch # Lists the branches
Problem 2: The merge caused unexpected conflicts
# Abort and review
git merge --abort
# Look at the changes before merging
git diff main feature/x
# Try again
git merge feature/x
Problem 3: I deleted a branch without merging it
# Check the reflog
git reflog
# Recover the branch
git branch feature/recovered <SHA>
Reflection and improvement
Post-project questions:
-
How many times did you switch branches?
- On real projects: 20-50 times a day.
-
Did you resolve the conflicts effectively?
- If not, redo the project with more practice.
-
Are your commit messages descriptive?
- Compare: "feat(auth): Add login" vs "update"
-
Did you clean up branches after merging?
- A critical habit on teams.
The professional workflow you learned
Your daily flow from now on:
# Morning: start a new feature
git switch main
git pull
git switch -c feature/new-feature
# During the day: frequent commits
git add .
git commit -m "feat: Part 1"
# ... more work ...
git commit -m "feat: Part 2"
# If an urgent hotfix comes in:
git stash
git switch main
git switch -c hotfix/urgent
# ... fix it ...
git switch main
git merge hotfix/urgent
git switch feature/new-feature
git stash pop
# When the feature is done:
git switch main
git pull
git merge --no-ff feature/new-feature
git branch -d feature/new-feature
git push origin main
Optional extensions
Extension 1: Gitflow Workflow
# Create the develop branch
git switch -c develop main
# Features branch off develop
git switch -c feature/x develop
# Merge into develop
git switch develop
git merge feature/x
# Release
git switch -c release/v1.0.0 develop
# ... testing ...
git switch main
git merge release/v1.0.0
git tag v1.0.0
Extension 2: Simulate a team
# Simulate a teammate working on the same file
git switch -c colleague-feature
# Create an intentional conflict
echo "// Colleague's code" >> src/products/products.js
git commit -am "feat: Colleague feature"
# Your simultaneous feature
git switch -c my-feature main
echo "// My code" >> src/products/products.js
git commit -am "feat: My feature"
# Merge and resolve
git switch main
git merge colleague-feature
git merge my-feature # CONFLICT
# ... resolve ...
Next steps
Now that you're comfortable with local branches:
- Module 5: GitHub and remote collaboration (push, pull, PRs)
- Module 6: Resolving conflicts in PRs
- Module 7: Code review and branch protection
But first: apply this workflow to your own personal project this week.
Additional resources
To keep practicing:
- Learn Git Branching - Interactive practice
- Git Katas - Advanced exercises
- Oh Shit, Git! - Fixes for common problems
- Atlassian Git Tutorials - Professional workflows
Module 4 summary
In this module you mastered:
✅ git branch - Create, list, delete branches
✅ git switch - Move between branches smoothly
✅ git merge - Fast-forward and 3-way merges
✅ Conflict resolution - By hand and with tools
✅ Branching strategies - Feature Branch, Gitflow
✅ A professional workflow - Features + hotfixes at the same time
With this, you have the skills to work with Git on a team.
Personal certification
If you completed the mini-project successfully:
🎉 Congratulations! You're now able to:
- Work on several features at the same time
- Handle urgent hotfixes without losing work
- Resolve conflicts with confidence
- Apply professional workflows
- Collaborate effectively on teams
Level reached: Git Branching Expert
Time invested: 60-75 minutes
Value gained: A professional branch workflow
Great work! 🚀
Next module: Module 5: GitHub and Remote Collaboration