DEV Community

Vigneshwaralingam
Vigneshwaralingam

Posted on

GitLab Day 3: Mastering Branching, Stashing, Merging, and More!

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • List all branches:
  git branch
Enter fullscreen mode Exit fullscreen mode
  • Switch between branches:
  git checkout feature-branch
Enter fullscreen mode Exit fullscreen mode

OR

  git switch feature-branch
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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, while git 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! πŸš€βœ¨


Top comments (0)