mirror of
https://github.com/thecyberlearn/devops-notes.git
synced 2026-08-18 07:32:51 +00:00
1.7 KiB
1.7 KiB
Git – Branching & Merging (Day 9)
Why Branching is Important?
Branching allows teams to:
- work on features safely
- fix bugs without breaking main code
- collaborate without conflicts
DevOps uses branching DAILY.
What is a Branch?
A branch is a separate line of development.
Main branch = stable production code
Feature branch = new changes
View Branches
git branch
Create a New Branch
git branch feature-login
Switch to branch:
git checkout feature-login
Shortcut (create + switch):
git checkout -b feature-login
Check Current Branch
git branch
(* shows active branch)
Make Changes in Branch
echo "Login feature" >> login.txt
git add .
git commit -m "add login feature"
Merge Branch into Main
Switch to main:
git checkout main
Merge:
git merge feature-login
Delete Branch (After Merge)
git branch -d feature-login
Merge Conflicts (Important)
Occurs when same file is changed in two branches.
Git will stop and ask you to fix manually.
Steps:
- Open conflicted file
- Fix content
- Save file
- Add & commit
git add .
git commit -m "resolve merge conflict"
Real DevOps Scenario
Problem: Multiple developers pushing code
Solution:
- Each dev uses own branch
- Merge after testing
Common Mistakes
- Working directly on main
- Not pulling latest code
- Deleting branch before merge
DevOps Rule
✅ One feature = one branch
❌ Direct commits to main
Summary
Today I learned Git branching, merging, and conflict handling. This is essential for DevOps collaboration.