📄 Notes Module 0.3 Git & GitHub

Git & GitHub —
Complete Beginner Notes

Everything you need to use Git professionally — from the four-stage model to branching strategies, SSH keys, and GitHub workflows for embedded systems development.

GoalProfessional-level Git for Embedded / IoT
Sections15 topics
LevelBeginner → Professional
1Foundations

Why Git Exists

Before Git, developers managed projects by duplicating files with different names:

project_final project_final2 project_final_latest project_final_latest_REAL

This becomes confusing and unmanageable extremely fast. Git was created to solve this problem entirely.

💾

Track Changes

Know exactly what changed, when, and who made the change.

🕐

Save History

Every commit is a permanent snapshot you can return to.

🌿

Feature Branches

Work on new features safely without breaking working code.

👥

Collaborate

Multiple engineers can work on the same project simultaneously.

2Foundations

Core Idea

Think of Git as a save game system for code. Every save point is called a Commit.

Commit A → Working LED blink Commit B → Added UART driver Commit C → Added OLED support Commit D → Fixed initialization bug

You can return to any commit at any time. This means you can experiment freely, knowing you can always get back to a working state.

💡
Mental Model
Git is a save game system. Every commit is a checkpoint. Bad change? Roll back to the last good commit instantly.
3Foundations

Git vs GitHub

Git — Local Software
Installed on your computer. Tracks file changes locally. Stores full commit history. Creates and manages branches. Works completely offline.
GitHub — Cloud Platform
Stores repositories online. Backs up your code. Enables team collaboration. Portfolio for employers. Hosts CI/CD pipelines.
💡
Simple way to remember
Git = the tool. GitHub = the cloud service that hosts what Git tracks. You can use Git without GitHub, but most professionals use both together.
4Foundations

Repository (Repo)

A Repository is a project folder managed by Git. Once you run git init, Git creates a hidden .git/ folder inside your project that stores the entire history.

bash
cd ESP32_Project
git init

After this, the folder becomes a Git repository. The .git/ directory contains everything Git needs — commit history, branch information, remote connections, and configuration.

Never delete .git/
The .git/ folder is the entire project history. Deleting it means losing every commit, branch, and tracked change permanently.
5Foundations

The Four-Stage Git Model

The most important concept in Git. Every file change moves through four stages before it reaches GitHub.

Working Directory edit & create files git add Staging Area selected changes git commit Local Repository commits on laptop git push Remote Repository GitHub git pull / git fetch

Every code change flows through all four stages. git add selects, git commit snapshots, git push uploads.

Stage 1 — Working Directory

Your actual project files. This is where you write code. Changes here are not yet tracked by Git in any permanent way.

Stage 2 — Staging Area

A temporary holding area. Think of it as a shopping cart — you choose which changes to include before checking out (committing).

bash
git add main.cpp          # add one file
git add .                 # add all changes

Stage 3 — Local Repository

A permanent snapshot stored on your machine. The commit creates a unique ID (hash) and stores the snapshot with your message.

bash
git commit -m "Add UART driver"

Stage 4 — Remote Repository

Your commits uploaded to GitHub — accessible from anywhere, backed up, and shareable.

bash
git push origin main
6Core Concepts

Commits

A commit is a permanent snapshot of your project. Every commit gets a unique hash ID, stores your message, the exact changes, who made them, and when.

bash
git commit -m "Add UART driver with baud rate config"

Every commit should represent one meaningful, logical change. Think of it as a save game checkpoint.

💡
Commit = Save Game
Every commit is a checkpoint you can return to. Commit early, commit often — at least after every feature or fix, not once at the end of the day.
7Core Concepts

Branches

A branch is an alternate timeline for your project. The main project continues normally while you experiment freely on a branch without any risk to working code.

A B C D E D main feature/wifi

The main branch stays stable. The feature/wifi branch develops independently. Both can advance simultaneously.

bash
# Create and switch to a new branch
git switch -c feature/wifi

# Switch back to main
git switch main

# List all branches
git branch
💡
Golden Rule
Never commit directly to main. Create a feature branch, develop and test there, then merge into main only after hardware testing passes.
8Core Concepts

Merge & Rebase

Merge

Combines a feature branch back into main. It creates a merge commit that preserves the full history of both branches.

bash
git switch main
git merge feature/wifi

Rebase

An alternative that replays commits on top of main, creating a cleaner linear history — but it rewrites commit hashes.

bash
git rebase main
Merge — for beginners
Safe for shared repositories. Preserves complete history. Creates a merge commit. Best choice when learning Git.
Rebase — advanced
Rewrites commit history. Never use on pushed commits. Creates cleaner history. Learn only after mastering merge.
9Core Concepts

.gitignore & Remote

.gitignore

Some files should never be committed — build artifacts, editor settings, secrets, and large auto-generated files. The .gitignore file tells Git which paths to always skip.

gitignore — .gitignore example for embedded projects
.pio/
build/
.vscode/settings.json
*.log
*.tmp
wifi_credentials.h
secrets.h

Remote

A remote is a named connection between your local repository and a GitHub repository. The default name is origin.

bash
# Connect local repo to GitHub
git remote add origin https://github.com/user/project.git

# See all remotes
git remote -v
10Core Concepts

Push, Pull & Clone

⬆️

Push — Laptop to GitHub

git push uploads all local commits to the remote repository.

⬇️

Pull — GitHub to Laptop

git pull downloads commits from GitHub and merges them into your local branch.

📥

Clone — Copy a Repo

git clone <url> downloads the complete repository including all history.

bash
git push origin main          # upload to GitHub
git pull origin main          # download from GitHub
git clone https://github.com/user/project.git  # copy repo
11Core Concepts

Stash, Restore, Reset & Revert

Stash — Temporary Drawer

Save unfinished work without committing it. Useful when you need to switch branches mid-task.

bash
git stash          # save unfinished work
git stash pop      # restore it later

Restore — Undo File Changes

Discard changes to a specific file, restoring it to the last committed state.

bash
git restore main.cpp

Reset — Dangerous Undo

Removes all uncommitted changes permanently. Use with extreme caution.

bash
git reset --hard HEAD   # nuclear button — cannot be undone
⚠️
Warning
git reset --hard permanently destroys all uncommitted work. There is no undo. Use git restore for single files instead.

Revert — Safe History Undo

Creates a new commit that reverses a previous commit — safe for shared repositories because it preserves history.

bash
git revert a3f8c1d    # safely undo a specific commit
12Core Concepts

Tags & SSH Keys

Tags — Permanent Version Markers

Tags mark important milestones — firmware releases, stable versions, deployment points.

bash
git tag -a v1.0.0 -m "First stable firmware release"
git push origin v1.0.0

SSH Keys — Secure GitHub Login

SSH keys provide secure, password-free authentication with GitHub. A key pair consists of a private key (stays on your machine) and a public key (uploaded to GitHub).

bash
ssh-keygen -t ed25519      # generate key pair
ssh -T git@github.com      # test the connection
Private Key (id_ed25519)
NEVER share this file. Stays on your computer only. Think: House key.
Public Key (id_ed25519.pub)
Upload to GitHub Settings. Safe to share. Think: Lock design.
13Professional Practices

Commit Message Rules

Commit messages are communication. They tell your future self and your teammates what changed and why.

✗ Bad commit messages
fix update changes final stuff wip
✓ Good commit messages
Add UART driver Fix OLED initialization timing Implement WiFi reconnect logic Update README with pinout diagram
  • Use the imperative mood: "Add UART driver" not "Added UART driver"
  • Keep the subject line under 50 characters
  • Each commit should represent one logical change
  • Start with a capital letter, no period at the end
14Professional Practices

Commands Reference

Daily Commands

bash — everyday workflow
git status             # see what changed
git add .              # stage all changes
git commit -m "msg"    # commit with message
git push               # upload to GitHub
git pull               # download from GitHub

Branch Commands

bash — branching
git switch -c feature/wifi   # create + switch
git switch main              # switch to main
git branch                   # list branches
git merge feature/wifi       # merge into current

History Commands

bash — inspecting history
git log --oneline      # compact history view
git diff               # see unstaged changes
git diff --staged      # see staged changes

Recovery Commands

bash — undoing things
git stash              # temporarily save work
git stash pop          # restore stashed work
git restore <file>     # undo file changes
git revert <commit>    # safely undo a commit
15Professional Practices

Embedded Workflow & Summary

Professional Workflow for Every Project

Create Repository ↓ Create Feature Branch ↓ Write Code ↓ Commit Frequently ↓ Test on Hardware ↓ Merge to Main ↓ Tag Release ↓ Push to GitHub

Mental Model Reference

ConceptMental ModelKey Command
RepositoryProject folder with historygit init
CommitSave game checkpointgit commit -m
BranchAlternate timelinegit switch -c
MergeCombine timelinesgit merge
RemoteGitHub connectiongit remote add
PushLaptop → GitHubgit push
PullGitHub → Laptopgit pull
CloneCopy repositorygit clone
StashTemporary drawergit stash
TagVersion milestonegit tag -a
SSH KeySecure login credentialssh-keygen
🚀 Final Advice for Embedded Engineers
  • Commit frequently — every feature, fix, or config change gets its own commit.
  • Write meaningful commit messages — your future self will thank you.
  • Keep main stable — only merge tested, hardware-validated code.
  • Push daily — GitHub is your backup, portfolio, and team communication tool.
  • Tag working releases — v1.0.0, v1.1.0 — so you can always return to a known-good state.
  • Use Issues for planning — even solo developers benefit from tracking bugs and features.

Code proves you can program. Git history proves you can engineer.

Git & GitHub — Complete Beginner Notes · Embedded Systems Foundations