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!












