DEV Community

Vigneshwaralingam
Vigneshwaralingam

Posted on

Day 2 Git & GitLab Learning Journey

Here’s a Day 2 Git & GitLab Learning Journey πŸŽ₯πŸš€.

Day 2 - Git & GitLab Mastery**

🎀 [INTRO]

"Hey everyone, welcome back to my Git & GitLab learning journey! This is Day 2, and today, I’ll be diving deep into essential Git commands, understanding staging areas, repositories, conflicts, and much more! So, let’s get started!"


πŸ› οΈ Step 1: Understanding Git & GitLab

"Git is a version control system that helps track changes in code. GitLab is a platform where we can store our repositories remotely."

  • Local Repository β†’ The repo on your computer.
  • Remote Repository β†’ The repo on GitLab or GitHub.
  • Working Directory β†’ Where you make changes to files.
  • Staging Area β†’ A temporary area where changes are added before committing.

πŸ“Œ Step 2: Basic Git Commands

πŸ‘‰ Adding files to the staging area

git add file_name
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This adds a specific file to the staging area.

πŸ‘‰ Adding all files to the staging area

git add .
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This stages all modified files at once.

πŸ‘‰ Checking the status of files

git status
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This shows which files are staged (green), untracked (red), or modified.

πŸ‘‰ Restoring changes before staging

git restore file_name
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This discards changes in the working directory before adding them to staging.


🎯 Step 3: Understanding File States in Git

πŸ’‘ Untracked (Red) β†’ New files that Git doesn’t know about yet.

πŸ’‘ Tracked (Green) β†’ Files that Git is tracking (staged or committed).

πŸ’‘ Staged β†’ Files ready to be committed.


⚠️ Step 4: Handling Merge Conflicts

"A conflict happens when two people edit the same file differently and push changes to the remote repo."

πŸ” Steps to resolve conflicts:

  1. Run:
   git pull origin main
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ This fetches the latest code and tries to merge it.

  1. If a conflict occurs, Git shows conflicted files.
  2. Open the file, find conflict markers like this:
   <<<<<<< HEAD
   Your code
   =======
   Someone else's code
   >>>>>>> another-branch
Enter fullscreen mode Exit fullscreen mode
  1. Manually edit the file to keep the correct changes.
  2. After resolving, stage and commit:
   git add .
   git commit -m "Resolved conflict"
   git push origin main
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Conflict resolved! πŸŽ‰


🎀 [OUTRO]

"That’s it for day 2nd Git & GitLab learning session! I’ve clearly understood how to use Git commands, handle conflicts, and work with repositories. If you found this helpful, don’t forget to like, share, and subscribe! See you in Day 3 of my learning journey! πŸš€πŸ”₯"


Top comments (0)