Skip to main content

Command Palette

Search for a command to run...

Git & GitHub Branching

Published
3 min read

If you're starting your developer journey (especially as a student or aspiring MERN stack dev), mastering Git workflow is non-negotiable.

In this guide, I’ll teach you step-by-step how to:

  • ✅ Create a GitHub repository

  • ✅ Create a develop branch

  • ✅ Create a feature branch

  • ✅ Commit your changes

  • ✅ Push branches to GitHub

  • ✅ Merge feature → develop

  • ✅ Push updated develop

  • ✅ Merge develop → main

This is a real-world workflow used in companies.


🧠 Why This Workflow?

Instead of working directly on main, professional teams follow:

main → production-ready code
develop → integration branch
feature/* → individual features

This keeps code clean and production safe.


🏗 Step 1: Create a GitHub Repository

  1. Go to GitHub

  2. Click New Repository

  3. Name it (example: inventory-app)

  4. Click Create repository

Now copy the HTTPS URL.

Example:

https://github.com/yourusername/inventory-app.git

💻 Step 2: Clone the Repository

git clone https://github.com/yourusername/inventory-app.git
cd inventory-app

Check branch:

git branch

By default, you’ll be on:

main

🌱 Step 3: Create a develop Branch

git checkout -b develop

Push it to GitHub:

git push -u origin develop

Now your repo has:

main
develop

✨ Step 4: Create a Feature Branch

Let’s say you're building a login feature.

git checkout develop
git checkout -b feature/login

Now you are working safely inside:

feature/login

📝 Step 5: Add & Commit Changes

After writing your code:

git add .
git commit -m "feat: add login functionality"

Pro Tip:
Use meaningful commit messages like:

  • feat: for features

  • fix: for bug fixes

  • refactor: for improvements


☁️ Step 6: Push Feature Branch

git push -u origin feature/login

Now go to GitHub → You’ll see a Compare & Pull Request option.


🔀 Step 7: Merge Feature → Develop

  1. Open Pull Request

  2. Base: develop

  3. Compare: feature/login

  4. Click Merge Pull Request

Done ✅


Option 2: Using Terminal

git checkout develop
git merge feature/login

🚀 Step 8: Push Updated Develop

After merging locally:

git push origin develop

Now develop contains your new feature.


🔥 Step 9: Merge Develop → Main (Release)

When your features are tested and stable:

git checkout main
git merge develop
git push origin main

Now production (main) is updated 🎉


📊 Final Branch Structure

main
develop
feature/login
feature/dashboard
feature/payment

🧼 Optional: Delete Feature Branch After Merge

git branch -d feature/login
git push origin --delete feature/login

Keeps your repo clean.


🎯 Real-World Flow Summary

1. Create repo
2. Create develop
3. Create feature branch from develop
4. Commit changes
5. Push feature
6. Merge feature → develop
7. Push develop
8. Merge develop → main