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
mainbranch 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 loghelps track commit history. - Working in branches prevents breaking the
mainbranch. -
git stashsaves temporary changes without committing. -
git mergecombines changes, whilegit rebasemakes 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! πβ¨
Top comments (0)