1. Introduction: Why Git & GitHub Rule Modern Software Engineering
In modern software engineering, writing code is only half the battle. Teams distributed across time zones build, test, and deploy complex systems consisting of hundreds of microservices. Git is the decentralized version control system created by Linus Torvalds in 2005 to manage the Linux kernel codebase, and GitHub is the global collaboration platform built on top of Git.
Whether you are a college student building your first portfolio or a staff engineer managing enterprise Kubernetes deployments, mastering Git's internal architecture, branching workflows, and conflict resolution is non-negotiable.
Access the interactive Notion checklist, command cheatsheets, and animated mental models on the official workspace:
π Open Official Notion Learning Path β2. Git's Internal Mental Model: The 3 Local Zones
Git does not track files as diffs or delta patches like older centralized systems (SVN or CVS). Instead, Git thinks of its data more like a series of snapshots of a miniature filesystem.
ββββββββββββββββββββββββ git add ββββββββββββββββββββββββ git commit ββββββββββββββββββββββββ
β Working Directory β βββββββββββββββββ> β Staging Area (Index)β βββββββββββββββββ> β Local Git Repository β
β (Untracked/Modified)β β (Ready for Snapshot)β β (.git / HEAD) β
ββββββββββββββββββββββββ <βββββββββββββββββ ββββββββββββββββββββββββ <βββββββββββββββββ ββββββββββββββββββββββββ
git restore git reset / revert
- Working Directory: The actual sandbox directory on your computer where you create, edit, and delete source files.
- Staging Area (Index): A binary index file located inside
.git/indexthat pre-formats and organizes the precise changes destined for the next commit snapshot. - Local Repository (.git folder): The permanent object store (Blobs, Trees, Commits, Annotated Tags) where Git permanently saves SHA-1 hashed immutable snapshots.
3. Initial Configuration & First-Time Setup
Before making any commits, configure your global developer identity and preferred default branch:
# 1. Set your global commit author name & email
git config --global user.name "Kashinath Chavan"
git config --global user.email "kashichavan7777@gmail.com"
# 2. Set default branch to main (standard across modern GitHub)
git config --global init.defaultBranch main
# 3. Configure auto-correct and sensible line-ending handling
git config --global core.autocrlf input
git config --global help.autocorrect 20
# 4. Verify your active configurations
git config --list --show-origin
4. Daily Core Workflow Commands
The core daily cycle of a software developer involves checking status, staging modified chunks, and creating meaningful atomic commit snapshots:
# Initialize a new local repository
git init
# Check the state of working directory and staging area
git status
# Stage specific files or all modified files
git add app.py requirements.txt
git add .
# Record a snapshot with a clean conventional commit message
git commit -m "feat(auth): implement JWT token verification middleware"
# Inspect detailed line-by-line diffs
git diff # Unstaged changes vs Staging area
git diff --staged # Staged changes vs Last commit (HEAD)
# View concise chronological commit history
git log --oneline --graph --decorate --all
5. Branching & Team Git Flow Strategies
In Git, a branch is simply a lightweight, movable 41-byte pointer to a commit hash. Creating a branch is virtually instantaneous and costs zero disk overhead.
# List all local and remote branches
git branch -a
# Create and switch to a new feature branch
git switch -c feature/payment-gateway-stripe
# (Legacy alternative: git checkout -b feature/payment-gateway-stripe)
# Switch back to the main branch
git switch main
# Rename a branch
git branch -m old-name new-name
# Delete a merged feature branch
git branch -d feature/payment-gateway-stripe
6. Merge vs. Rebase: The Architectural Debate
When integrating feature branch code back into the main branch, developers choose between two strategies:
| Feature | git merge |
git rebase |
|---|---|---|
| History Style | Preserves true historical timeline with explicit 2-parent merge commits | Creates a perfectly linear, clean single-line commit history |
| Commit Hashes | Preserves original commit SHAs | Re-writes new commit hashes by replaying commits onto target HEAD |
| Golden Rule | Safe for shared public branches (main, develop) | NEVER rebase a shared/public branch already pushed to remotes! |
# Standard Merge (from main)
git switch main
git merge feature/payment-gateway-stripe
# Interactive Rebase (squashing messy commits before submitting PR)
git rebase -i HEAD~3
7. Resolving Merge Conflicts Step-by-Step
Conflicts occur when two developers alter the exact same line of code in different branches. Git halts the merge and injects conflict markers into the source file:
<<<<<<< HEAD (Current branch: main)
PAYMENT_GATEWAY = "STRIPE_ENTERPRISE_V2"
=======
PAYMENT_GATEWAY = "PAYPAL_PRO_SANDBOX"
>>>>>>> feature/payment-gateway-paypal (Incoming branch)
To resolve:
- Open the file, delete the conflict markers (
<<<<<<<,=======,>>>>>>>), and keep the desired production code. - Stage the resolved file:
git add payment_settings.py - Complete the commit:
git commit -m "fix(merge): resolve payment gateway conflict between Stripe and PayPal"
8. Undoing Changes & Safety Nets
# 1. Discard uncommitted changes in a specific file
git restore filename.py
# 2. Unstage a file without losing local edits
git restore --staged filename.py
# 3. Temporarily stash uncommitted work to switch branches quickly
git stash save "WIP: half-finished login refactor"
git stash list
git stash pop
# 4. Safely undo a pushed commit by creating a new inverse commit
git revert <commit-hash>
# 5. Reset HEAD (Soft = keep in staging, Hard = permanently discard)
git reset --soft HEAD~1 # Undo commit, keep changes staged
git reset --hard HEAD~1 # β οΈ Danger: completely destroy last commit and working files
# 6. The Ultimate Git Safety Net: REFLOG
# Recovers "lost" or deleted commits and branches!
git reflog
git checkout -b recovered-branch HEAD@{3}
9. Remote Collaboration on GitHub
# Link a local repository to GitHub
git remote add origin https://github.com/kashichavan/updatezbykashi.git
# Push local main branch and set upstream tracking
git push -u origin main
# Fetch changes from remote without merging
git fetch origin
# Fetch and immediately merge remote changes into current branch
git pull origin main
# Clean up stale local references to remote deleted branches
git fetch --prune
10. Professional Pull Request (PR) & Open Source Etiquette
- Keep PRs Small & Focused: A PR with 150 lines of code across 3 files is reviewed in 10 minutes. A PR with 2,500 lines across 80 files is delayed for weeks.
- Write Descriptive PR Descriptions: Mention Why this change is made, What approaches were tested, and link the related issue ticket.
- Run Linting & Unit Tests Locally: Ensure
python manage.py testpasses and code formatting adheres to PEP 8 / Prettier before opening the PR. - Squash Work-in-Progress Commits: Turn 15 messy "fix typo", "test again" commits into 1 clean logical commit before merge.
Ready for the Full Interactive Learning Path?
Explore the full Notion workspace with copy-paste workflows, interactive flashcards, and advanced Git architecture diagrams.
π Open Git & GitHub Complete Learning Path on Notion β