Mastery in Git – The Complete Guide
From Basics to Advanced DevOps Automation
πŸ’‘ β€œCode is temporary, but version control is forever.”
Amit Kumar Singh πŸ‘¨β€πŸ’»
Dedication
β€œDedicated to all learners who believe in mastering their craft.”

Preface

This guide is created to empower developers, IT professionals, and learners to master Git and GitHub through real-world concepts, examples, and workflows. Whether you're building solo projects or leading enterprise teams, this book will help you work faster, safer, and smarter with version control.

Dedication

Dedicated to all learners who believe in mastering their craft.

Table of Contents (Interactive)

Part 1: Git Basics

What is Git?

Git is a distributed version control system (VCS) used to track changes in code. Every developer has a full copy of the repository, enabling offline work and safe collaboration.

Why use Git?

Where & How to use Git

Use Git for software projects (web, mobile, APIs). Typical flow:

Working Directory -> Staging Area -> Local Repository -> Remote Repository

Getting started (Setup)

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git init          # Initialize a repo
git clone    # Clone a remote repo

Essential Commands

Branching

Branches isolate work.

git branch              # list branches
git branch feature-x     # create branch
git checkout feature-x   # switch branch
git checkout -b feat/one # create & switch
git merge feature-x      # merge into current

Remote Repositories

git remote add origin 
git push -u origin main
git pull
git fetch

Undoing changes

Part 2: Advanced Git

Merge vs Rebase

Merge preserves history and creates merge commits. Use for public branches. Rebase rewrites commits to create a linear history; use on local feature branches before merging.

Handling Merge Conflicts

When conflicts occur, edit files to resolve markers (<<<<<< etc.), then git add and git commit.

Stash

git stash          # save uncommitted work
git stash list
git stash apply     # reapply stash
git stash pop       # apply and remove

Tags

Tags mark releases.

git tag v1.0
git tag -a v1.0 -m "Release 1.0"
git push origin v1.0

Cherry-pick

Apply an individual commit from another branch:

git cherry-pick <commit_id>

Revert vs Reset

git revert <id> creates a new commit to undo changes (safe). git reset moves HEAD (rewrites history, be careful).

Useful Logs & Visualization

git log --oneline
git log --graph --oneline --decorate
git show <commit>

Advanced Tips

Part 3: GitHub Projects & CI/CD Integration

What is GitHub?

GitHub hosts Git repositories and adds collaboration tools: PRs, Issues, Actions (CI/CD), Projects (kanban), and security features.

Branching Strategies

Common strategies:

Pull Requests & Code Review

Create feature branch β†’ push β†’ open PR β†’ assign reviewers β†’ merge after approval. Keep PRs small and focused. Use templates and checks.

GitHub Actions (CI/CD)

Automate building, testing, and deploying. Example workflow for Laravel (YAML):

name: Laravel CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with: { php-version: '8.2' }
      - run: composer install
      - run: php artisan test

Deploying (example: Hostinger via FTP)

- uses: SamKirkland/FTP-Deploy-Action@v4.3.2
  with:
    server: ${{ secrets.FTP_SERVER }}
    username: ${{ secrets.FTP_USERNAME }}
    password: ${{ secrets.FTP_PASSWORD }}

Automated Quality Checks

Run unit tests, linters (ESLint), formatters (Prettier), and dependency checks (Dependabot) in your CI pipeline.

Part 4: GitHub Advanced β€” Issues, Releases & Security

Issues

Use Issues for bugs, tasks, and feature requests. Use labels, assignees, and milestones. Reference issues in commits: closes #12 will auto-close the issue on merge.

Projects (Kanban)

Use Projects to manage progress visually: To Do β†’ In Progress β†’ Done. Link issues and PRs to cards for traceability.

Releases

Create releases to tag and document stable versions. Use annotated tags and attach build artifacts if needed.

Wiki & Discussions

Use Wiki for project docs and Discussions for broader community Q&A and idea brainstorming.

Repository Security

Collaborator Roles

Define roles (Owner, Admin, Maintainer, Write, Read) and set team permissions. Use CODEOWNERS to auto-request reviews for specific paths.

Part 5: Git + GitHub for Teams & Open Source Collaboration

Fork vs Clone

Clone copies a repo you control locally. Fork copies someone else's repo to your account for contributions.

Typical Open Source Workflow

  1. Fork the original repo on GitHub
  2. Clone your fork locally
  3. Create a feature branch: git checkout -b feature/xyz
  4. Make changes, commit, push to your fork
  5. Open a PR to the original repo

Contributing Guidelines

Provide a CONTRIBUTING.md describing branch naming, testing, commit messages, and how to open PRs.

CODEOWNERS

/api/*    @backend-team
/frontend/* @frontend-team

Maintaining Clean History

Use interactive rebase (git rebase -i main) and squash to keep commit history clean before merging.

Syncing a Fork

git remote add upstream https://github.com/original/repo.git
git fetch upstream
git checkout main
git merge upstream/main

Large Repos & Git LFS

Use Git LFS for large binaries (git lfs track "*.zip"). Remove unnecessary large files from history if needed.

Part 6: Git Mastery Summary & Interview Preparation

Summary Overview

Git empowers teams and individuals to manage code changes, collaborate, and automate workflows. This book covered fundamentals through advanced CI/CD, security, and open-source collaboration.

Real-world Project Example

Example: Adding a leaderboard to a Laravel app.

git checkout -b feature/leaderboard
# implement UI and API
git add .
git commit -m "Added leaderboard UI"
git push origin feature/leaderboard
# open PR and merge after review

Troubleshooting Scenarios

Interview Q&A (Short)

Q: Difference between Git and SVN?
A: Git is distributed; SVN is centralized.

Q: Pull vs Fetch?
A: git fetch downloads; git pull downloads and merges.

Q: Rebase vs Merge?
A: Rebase rewrites history making it linear; Merge preserves branch history.

Career Roadmap

Amit Kumar Singh πŸ‘¨β€πŸ’»

Amit is an IT Executive and developer passionate about technology, DevOps, and continuous learning. He created the Git Mastery series to help others gain real-world version control expertise.

GitHub: https://github.com/amit2x

Thank you for reading β€” Keep Coding!
Find more at
https://github.com/amit2x
Β© 2025 Amit Kumar Singh β€” All Rights Reserved
Amit Kumar Singh | Git Mastery