Git Branches: How I Stopped Breaking Code and Started Building with Confidence

Share with friends
Save Story for Later (0)
Please login to bookmark Close


๐ŸŒฑ How I First Broke Everything (and What It Taught Me)

When I first started using Git about a decade ago, I thought I was being smart by making changes directly on the main branch.

Spoiler alert: I wasnโ€™t. One day, I pushed some half-baked code to production, and everything fell apart. It was a painful lessonโ€”but it led me to discover Git branches, and everything changed from there.

If youโ€™re tired of feeling anxious every time you commit code, this post is for you. Letโ€™s dive into how Git branches can help you become a more confident SDET.


๐ŸŒณ What is a Git Branch?

Imagine youโ€™re writing a novel ๐Ÿ“–. Youโ€™re happy with Chapter 1, but now you want to experiment with Chapter 2 without messing up the original. Instead of editing the main file, you make a copy, work on the copy, and merge it back if it works. Thatโ€™s exactly what a Git branch does in code.

A branch is simply a lightweight movable pointer to a specific commit. You can think of the main branch as your primary storyline, and other branches as side quests or experiments you can safely run.


๐Ÿ’ก Why Branches Matter

  • ๐Ÿงช Safe experimentation: Try out new features without affecting the main code.
  • ๐Ÿ‘ฅ Collaboration: Multiple developers can work in parallel without stepping on each otherโ€™s toes.
  • ๐Ÿ’พ History: You can always trace back and understand what changes happened, where, and why.

๐Ÿ”จ Essential Git Branch Commands (Without the Confusion)

Hereโ€™s how you start working with branches like a pro.

โœ… git branch โ€“ View or Create Branches

  • git branch โ†’ Lists all branches
  • git branch new-feature โ†’ Creates a new branch called new-feature

โœจ Pro Tip: Add a naming convention like feature/signup-form or bugfix/login-error for better clarity.

๐Ÿ” git checkout โ€“ Switch Between Branches

  • git checkout new-feature โ†’ Switches to the new-feature branch

๐ŸŽฏ Pro Tip: Starting from Git 2.23, you can also use:

  • git switch new-feature

Itโ€™s simpler and more intuitive.

๐Ÿงฌ git merge โ€“ Bring Changes Together

  • git merge new-feature โ†’ Merges changes from new-feature into your current branch (usually main)

โš ๏ธ Warning: Always pull the latest changes before merging to avoid conflicts.


๐Ÿค Real-Life Example: Adding a Contact Form

Letโ€™s say youโ€™re building a website and want to add a contact form.

  1. Create a branch:
    git branch contact-form
  2. Switch to it:
    git checkout contact-form
  3. Build your feature.
  4. When done, switch back to main:
    git checkout main
  5. Merge it in:
    git merge contact-form

Voila! Your feature is live and your main branch remained untouched until it was ready. ๐Ÿงผ


๐ŸŽฏ Expert Tips & Best Practices

โœ… Keep branches small and focused
One branch = one task. This keeps code reviews quick and reduces merge conflicts.

โœ… Use pull requests (PRs)
Even if you work solo, PRs help document your thought process and keep code review in check.

โœ… Delete old branches
Once merged, remove them with git branch -d branch-name to keep things tidy ๐Ÿงน

โœ… Name branches clearly
Use formats like feature/, bugfix/, or hotfix/ to indicate purpose.


โš ๏ธ Common Mistakes to Avoid

โŒ Working directly on main
Itโ€™s risky. Always branch off.

โŒ Not pulling the latest changes before merging
This often leads to conflicts. Always sync first: git pull

โŒ Merging without testing
Test your feature branch before merging into main.


Your Next Git Moves

Using Git branches was a turning point in my SDET journey. It turned chaos into calm and gave me the confidence to experiment, collaborate, and grow.

๐Ÿ‘ฃ Next Steps:

  • Create your first branch today!
  • Start using git switch for a smoother experience.
  • Write cleaner branch names that your future self will thank you for.

๐Ÿ“š Bonus: Git Branch Cheatsheet

  • git branch โ†’ List branches
  • git branch new-branch โ†’ Create branch
  • git checkout branch-name โ†’ Switch to branch
  • git merge branch-name โ†’ Merge into current branch
  • git branch -d branch-name โ†’ Delete branch

๐Ÿ’ฌ Got Questions or Branch Nightmares?

Drop them in the comments or DM meโ€”Iโ€™ve broken plenty of things and lived to tell the tale. ๐Ÿ˜‰

Article Contributors

  • (Author)
    Test Lead, Paisabazaar.com

    Driving Quality Excellence in Software Development | Expert in Test Planning, Automation, and Continuous Improvement | Enabling Teams to Deliver High-Quality Software | Lifelong Learner | Let's Elevate Testing Together!

  • Ishan Dev Shukl
    (Reviewer)
    SDET Manager, Nykaa

    With 13+ years in SDET leadership, I drive quality and innovation through Test Strategies and Automation. I lead Testing Center of Excellence, ensuring high-quality products across Frontend, Backend, and App Testing. "Quality is in the details" defines my approachโ€”creating seamless, impactful user experiences. I embrace challenges, learn from failure, and take risks to drive success.

Subscribe to QABash Weekly ๐Ÿ’ฅ

Dominate โ€“ Stay Ahead of 99% Testers!

Leave a Reply

Scroll to Top