惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
I
InfoQ
博客园_首页
G
Google Developers Blog
爱范儿
爱范儿
Last Week in AI
Last Week in AI
量子位
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
月光博客
月光博客
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Day 4 — Git & GitHub Fundamentals
Rahul Joshi · 2026-05-15 · via DEV Community

Modern software development is impossible without version control. Whether you're building applications alone, working in a startup, contributing to open source, or managing enterprise infrastructure — Git and GitHub are at the center of everything.

From tracking code changes to handling production deployments, Git powers modern engineering workflows.

In this guide, we’ll deeply cover:

  • What Git actually is
  • How Git works internally
  • Git basics
  • Branching strategies
  • Pull Requests
  • Merge conflicts
  • Git workflows
  • Essential Git commands
  • Best practices used by professional teams

🔗 Resources


🌍 What is Git?

Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005.

Git helps developers:

  • Track changes in code
  • Collaborate safely
  • Maintain project history
  • Revert mistakes
  • Manage releases
  • Work on multiple features simultaneously

🧠 Why Git Was Created

Before Git, developers mainly used centralized systems like:

  • SVN
  • CVS

These systems had problems:

  • Slow performance
  • Central server dependency
  • Difficult branching
  • Risk of losing history

Git solved these issues by making every developer’s machine a complete copy of the repository.

That means:

  • Faster operations
  • Offline work
  • Safer collaboration
  • Better branching support

🔥 What Makes Git Powerful?

Feature Why It Matters
Distributed architecture Every developer has full repository history
Fast branching Lightweight feature development
Snapshots Tracks repository states efficiently
Data integrity Uses SHA hashing
Collaboration Multiple developers work safely

🌐 What is GitHub?

GitHub is a cloud-based platform that hosts Git repositories.

GitHub adds:

  • Remote repository hosting
  • Collaboration tools
  • Pull Requests
  • CI/CD integration
  • Code review systems
  • Security scanning
  • Issue tracking
  • Open-source collaboration

Think of it like this:

Tool Purpose
Git Version control engine
GitHub Collaboration platform

⚙️ Understanding How Git Works Internally

Many beginners struggle here, but once you understand Git’s internal workflow, everything becomes easier.

Git has three main areas:


1️⃣ Working Directory

This is your actual project folder.

Example:

app.js
package.json
README.md

Enter fullscreen mode Exit fullscreen mode

You edit files here.


2️⃣ Staging Area (Index)

This is Git’s preparation area.

You choose which changes should go into the next commit.

Example:

git add app.js

Enter fullscreen mode Exit fullscreen mode

Now app.js is staged.


3️⃣ Repository (.git)

This stores:

  • Commit history
  • Branches
  • Metadata
  • References

This is Git’s database.


📦 Git Repository Structure

When you initialize Git:

git init

Enter fullscreen mode Exit fullscreen mode

Git creates:

.git/

Enter fullscreen mode Exit fullscreen mode

Inside .git:

  • Objects
  • References
  • Commit history
  • Configuration
  • Branch metadata

⚠️ Never manually modify .git.


🚀 Git Basics

📁 Initializing a Repository

git init

Enter fullscreen mode Exit fullscreen mode

This turns your project into a Git repository.


📥 Cloning a Repository

git clone https://github.com/user/project.git

Enter fullscreen mode Exit fullscreen mode

This downloads:

  • Files
  • Commit history
  • Branches
  • Remote configuration

📊 Checking Repository Status

git status

Enter fullscreen mode Exit fullscreen mode

Shows:

  • Modified files
  • Staged changes
  • Untracked files

This command becomes your best friend.


➕ Staging Changes

Stage everything:

git add .

Enter fullscreen mode Exit fullscreen mode

Stage a single file:

git add server.js

Enter fullscreen mode Exit fullscreen mode


💾 Creating Commits

git commit -m "Added authentication middleware"

Enter fullscreen mode Exit fullscreen mode

A commit is:

  • A snapshot
  • A checkpoint
  • A historical record

🧾 Good Commit Messages

❌ Bad:

git commit -m "fix"

Enter fullscreen mode Exit fullscreen mode

✅ Good:

git commit -m "Fixed JWT token expiration handling"

Enter fullscreen mode Exit fullscreen mode

Professional teams use:

  • Clear descriptions
  • Small commits
  • Atomic changes

🌿 Understanding Branches

Branches are one of Git’s biggest strengths.

A branch is simply a movable pointer to commits.


🏗️ Why Branches Matter

Without branches:

  • Everyone edits the same code
  • Features collide
  • Production becomes unstable

Branches solve this.


🔹 Creating Branches

git branch feature-login

Enter fullscreen mode Exit fullscreen mode

Switch to branch:

git checkout feature-login

Enter fullscreen mode Exit fullscreen mode

Modern shortcut:

git checkout -b feature-login

Enter fullscreen mode Exit fullscreen mode


🔍 Viewing Branches

git branch

Enter fullscreen mode Exit fullscreen mode

Current branch shows:

* main

Enter fullscreen mode Exit fullscreen mode


🔀 Merging Branches

Merge feature into main:

git checkout main
git merge feature-login

Enter fullscreen mode Exit fullscreen mode

Git combines histories.


⚠️ Merge Conflicts

Conflicts happen when:

  • Two developers edit the same lines
  • Git cannot automatically decide

Example conflict:

<<<<<<< HEAD
console.log("Old Code");
=======
console.log("New Code");
>>>>>>> feature-login

Enter fullscreen mode Exit fullscreen mode

You must manually resolve it.


🌳 Branching Strategies

1️⃣ Feature Branch Workflow

Each feature gets a separate branch.

Example:

feature-payment
feature-auth
feature-dashboard

Enter fullscreen mode Exit fullscreen mode

Flow

  1. Create branch
  2. Develop feature
  3. Open Pull Request
  4. Review
  5. Merge

Advantages

  • Cleaner history
  • Safer development
  • Easy rollback

Most startups use this.


2️⃣ Git Flow

One of the most famous workflows.

Popularized by Vincent Driessen.


Git Flow Branches

Git Flow

Branch Purpose
main Production-ready
develop Integration branch
feature/* New features
release/* Release preparation
hotfix/* Emergency fixes

Git Flow Lifecycle

🔹 Feature Development

git checkout develop
git checkout -b feature-auth

Enter fullscreen mode Exit fullscreen mode


🔹 Release Creation

git checkout -b release-v1.0

Enter fullscreen mode Exit fullscreen mode


🔹 Hotfix Production Bugs

git checkout main
git checkout -b hotfix-login

Enter fullscreen mode Exit fullscreen mode


✅ Advantages

  • Organized releases
  • Stable production
  • Enterprise friendly

❌ Disadvantages

  • Complex workflow
  • Too many branches
  • Slower deployments

3️⃣ Trunk-Based Development

Used heavily in:

  • DevOps teams
  • CI/CD environments
  • Cloud-native engineering

Core idea:

  • Small commits
  • Frequent merges
  • Short-lived branches

Main branch = trunk.


✅ Benefits

  • Faster deployments
  • Smaller conflicts
  • Continuous integration friendly

Popular in:

  • Google
  • Netflix
  • Meta

🔄 Pull Requests (PRs)

A Pull Request is a proposal to merge code changes.

PRs are central to modern collaboration.


🧩 Pull Request Lifecycle

Step 1 — Create Branch

git checkout -b feature-auth

Enter fullscreen mode Exit fullscreen mode


Step 2 — Push Branch

git push origin feature-auth

Enter fullscreen mode Exit fullscreen mode


Step 3 — Open PR on GitHub

GitHub compares:

  • Source branch
  • Target branch

Step 4 — Code Review

Teams review:

  • Logic
  • Security
  • Readability
  • Performance

Step 5 — CI/CD Runs

Automated checks:

  • Tests
  • Linting
  • Security scans

Step 6 — Merge PR

Once approved:

  • Squash merge
  • Rebase merge
  • Standard merge

🔐 Why Pull Requests Matter

PRs improve:

  • Code quality
  • Security
  • Team collaboration
  • Knowledge sharing

They act like a checkpoint before production.


🧠 Types of Git Merges

🔹 Fast Forward Merge

Simple linear merge.

Occurs when no divergence exists.


🔹 Three-Way Merge

Git creates a merge commit.

Most common in teams.


🔹 Squash Merge

Combines all commits into one.

Creates cleaner history.


🔹 Rebase

Moves commits on top of the latest branch.

Example:

git rebase main

Enter fullscreen mode Exit fullscreen mode

Benefits

  • Linear history
  • Cleaner logs

Risk

  • Can rewrite history

⚙️ Common Git Workflows

1️⃣ Centralized Workflow

Everyone pushes to the same branch.

Simple but risky.

Best for:

  • Small teams
  • Learning

2️⃣ Feature Branch Workflow

Separate branches for features.

Most commonly used workflow today.


3️⃣ Forking Workflow

Mostly used in open source.

Flow

  1. Fork repository
  2. Clone fork
  3. Create branch
  4. Push changes
  5. Open PR to original repo

Used heavily on GitHub.


🚨 Common Git Problems

❌ Detached HEAD State

Occurs when checking out commits directly.

Example:

git checkout 93f4c2

Enter fullscreen mode Exit fullscreen mode

You are no longer on a branch.


❌ Force Push Problems

git push --force

Enter fullscreen mode Exit fullscreen mode

Dangerous because:

  • Rewrites history
  • Can delete teammates’ work

Use carefully.


❌ Huge Commits

Huge commits are bad because:

  • Hard to review
  • Hard to debug
  • Hard to revert

🧹 Git Best Practices

✅ Commit Frequently

Small commits = easier debugging.


✅ Use Meaningful Branch Names

✅ Good:

feature-payment-api
bugfix-auth-timeout

Enter fullscreen mode Exit fullscreen mode

❌ Bad:

test123
newbranch

Enter fullscreen mode Exit fullscreen mode


✅ Protect Main Branch

Never directly push production-breaking code.


✅ Pull Before Push

git pull origin main

Enter fullscreen mode Exit fullscreen mode

Avoids conflicts.


✅ Use .gitignore

Prevent sensitive or unnecessary files.

Example:

node_modules/
.env
dist/
coverage/

Enter fullscreen mode Exit fullscreen mode


🔐 Git in DevOps & CI/CD

Git is deeply integrated into:

  • CI/CD pipelines
  • Infrastructure as Code
  • Kubernetes deployments
  • DevSecOps automation

Modern pipelines trigger automatically when:

  • Code is pushed
  • PRs are merged
  • Releases are tagged

Popular integrations:

  • GitHub Actions
  • GitLab CI/CD
  • Jenkins
  • CircleCI

🚀 Final Thoughts

Git is more than just commands.

It’s a system that enables:

  • Safe collaboration
  • Scalable development
  • Reliable deployments
  • Modern DevOps practices

Once you truly understand:

  • Branching
  • Commits
  • PRs
  • Workflows
  • Collaboration strategies

…you stop being just a coder and start working like a professional software engineer.

The best way to master Git is:

  • Use it daily
  • Break things
  • Resolve conflicts
  • Work on real projects

Because every professional developer spends a huge part of their career inside Git.