Today’s learning focused on one of the most powerful features of Git — branching and merging. This concept is essential for real-world development, especially when working in teams or managing multiple features simultaneously.
🚀 What is Branching?
A branch in Git is essentially a separate line of development. It allows you to work on new features, bug fixes, or experiments without affecting the main codebase.
By default, every repository starts with a branch called:
-
main(or sometimesmaster)
🌿 Why Use Branches?
- Develop features independently
- Fix bugs without disturbing stable code
- Collaborate with team members efficiently
- Maintain clean project history
🛠️ Important Branching Commands
1. Check existing branches
git branch
2. Create a new branch
git branch feature1
3. Switch to a branch
git checkout feature1
👉 Modern alternative (recommended):
git switch feature1
4. Create and switch in one step
git checkout -b feature2
👉 Modern alternative:
git switch -c feature2
5. Delete a branch
git branch -d feature1
👉 Force delete (if not merged):
git branch -D feature1
🔀 What is Merging?
Merging is the process of combining changes from one branch into another.
Typically:
- Work is done in a feature branch
- Then merged into
mainafter completion
🔧 Important Merging Commands
1. Switch to target branch (usually main)
git checkout main
2. Merge another branch into current branch
git merge feature2
⚠️ Merge Conflicts
Sometimes, Git cannot automatically merge changes. This happens when:
- Same file
- Same lines modified in different branches
In such cases:
- Git marks conflict in files
- You manually resolve it
- Then run:
git add .
git commit -m "Resolved merge conflict"
📊 Useful Commands for Workflow
Check branch status
git status
View commit history
git log --oneline --graph --all
Push branch to GitHub
git push origin feature2
Pull latest changes before merging
git pull origin main
🧠 Key Takeaways
- Branching allows safe and parallel development
- Always create a branch before starting new work
- Merge carefully and handle conflicts properly
- Keep your branches updated with
mainregularly
📌 Final Thought
Branching and merging are the backbone of collaborative development in Git. Once mastered, they make your workflow cleaner, safer, and much more professional.
Today was a major step forward in understanding how real-world development actually happens!
Top comments (0)