Day-31: Git Branching & Merging — Summary


🌿 1️⃣ What is Branching in Git?

Branching in Git allows you to work on different versions of a project simultaneously — without affecting the main codebase.

It’s like creating a separate workspace to develop a new feature, fix a bug, or test an idea safely.


⚙️ 2️⃣ Common Branch Commands

Command Description
git branch Lists all branches in your repo
git branch <name> Creates a new branch
git checkout <branch> Switches to a branch
git checkout -b <branch> Creates and switches to a new branch
git merge <branch> Merges another branch into current one
git branch -d <branch> Deletes a branch

🧩 3️⃣ Typical Workflow

# create a new branch
git checkout -b feature-login

# make code changes and commit
git add .
git commit -m "Added login feature"

# switch back to main branch
git checkout main

# merge new feature into main
git merge feature-login

🧠 This workflow keeps your main branch stable while allowing parallel development.


🔀 4️⃣ What is Merging?

git merge combines changes from one branch into another.

After merging, both branch histories are preserved — making it easy to track changes.

Example:

git checkout main
git merge feature-login

✅ Result:

Your main branch now includes all commits from feature-login.