GitLab learning journey:
🚀 GitLab Day 3: Mastering Git Branching & Workflow
📌 Introduction
Today, I deep-dived into GitLab's version control system, focusing on branches, logs, stashing, merging, rebasing, and more. Understanding these concepts is crucial for efficient collaboration in software development.
📝 What I Learned Today
1️⃣ Git Log: Tracking Changes
The git log
command allows me to see the commit history, making it easier to track changes over time.
git log --oneline --graph --decorate --all
This helps visualize the commit history in a simple and structured way.
2️⃣ Git Branch: Working with Different Versions
Branches allow developers to work on features separately without affecting the main
branch. I learned how to:
- Create a branch:
git branch feature-branch
- List all branches:
git branch
- Switch between branches:
git checkout feature-branch
OR
git switch feature-branch
3️⃣ Why Work on a Branch Instead of main
?
- Keeps the
main
branch stable. - Allows multiple developers to work simultaneously.
- Prevents code conflicts before merging changes.
4️⃣ Stashing: Temporarily Saving Changes
Sometimes, I need to switch branches but don’t want to commit my current changes. That’s where git stash
helps.
git stash
git switch another-branch
git stash pop # Bring back my stashed changes
This ensures I don't lose any uncommitted work when changing branches.
5️⃣ Merging: Combining Changes
Once the feature is ready, I need to merge it back into the main
branch.
git checkout main
git merge feature-branch
If conflicts arise, Git will prompt me to resolve them before finalizing the merge.
6️⃣ Rebasing: A Cleaner Alternative to Merge
Instead of a normal merge, I also learned about git rebase
, which rewrites commit history to keep it clean.
git rebase main
This avoids unnecessary merge commits, making the history more linear and readable.
7️⃣ Pushing Changes to GitLab
After making changes locally, I can push them to the remote repository using:
git push origin feature-branch
Now, my changes are available for review and collaboration on GitLab!
🎯 Key Takeaways
-
git log
helps track commit history. - Working in branches prevents breaking the
main
branch. -
git stash
saves temporary changes without committing. -
git merge
combines changes, whilegit rebase
makes history cleaner. - Pushing changes to GitLab allows for easy collaboration.
💡 Final Thoughts
Day 3 of learning GitLab was insightful! Understanding branching strategies is essential for teamwork and smooth development workflows. Tomorrow, I plan to explore pull requests, CI/CD, and GitLab pipelines.
Stay tuned for more updates! 🚀✨