π― If you're a DevOps beginner or fresher learning Git workflows, this guide is for you. Weβll create a simple project and practice Feature Branching step-by-step on an Ubuntu-based EC2 instance.
π§° What Youβll Learn:
- How Feature Branching works
- How to use Git to isolate feature development
- How to merge cleanly into main
- A real-world example using a simple HTML app
π₯οΈ Environment Setup
I'm running this on a Ubuntu EC2 instance that has Git installed.
You can follow along from:
- EC2 or Your local machine
- Git Bash or Linux terminal
π Step 1: Create a Project Directory
mkdir myshop-demo
cd myshop-demo
Create a basic index.html file:
<!DOCTYPE html>
<html>
<head>
<title>MyShop Demo</title>
</head>
<body>
<h1>Welcome to MyShop</h1>
<p>Your favorite online store!</p>
<div class="product">
<h2>Product Name</h2>
<p>$19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>
Save the file inside myshop-demo/.
πΏ Step 2: Initialize a Git Repository
git init
β Step 3: Add and Commit Initial Code
git add index.html
git commit -m "Initial commit - MyShop homepage"
π± Step 4: Create a Feature Branch
Letβs say we want to add a "Wishlist" button.
git checkout -b feature/add-to-wishlist
This creates a new branch for the feature β safely isolated from main.
βοΈ Step 5: Make Your Feature Change
Edit index.html and add the Wishlist button after Add to Cart
<button>Add to Wishlist</button>
πΎ Step 6: Save and Commit the Change
git add index.html
git commit -m "Added Add to Wishlist button"
π Step 7: Merge Back to Main
Once your feature is done and tested:
git checkout main
git merge feature/add-to-wishlist
π Feature successfully merged into production code!
π§ What You Learned
β
How to isolate features
β
How to prevent breaking main
β
How to merge safely after testing
π Why Use Feature Branching?
β Pros | π« Cons |
---|---|
Easy to manage individual features | Too many branches if not cleaned |
Safe from breaking main | Might create merge conflicts if team doesnβt sync often |
Perfect for small teams | Can slow down big, fast-moving teams |
π§ͺ Whatβs Next?
Now that you've nailed Feature Branching, try the next one:
β‘οΈ [Gitflow Branching Strategy β Hands-On With HTML Project]
π¬ Have questions or want to practice together? Drop a comment!
π§‘ If this helped you, give it a β€οΈ or π¦ so other beginners can find it too!
Top comments (0)