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.
Why Git Exists
Before Git, developers managed projects by duplicating files with different names:
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.
Core Idea
Think of Git as a save game system for code. Every save point is called a Commit.
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.
Git vs GitHub
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.
cd ESP32_Project
git initAfter this, the folder becomes a Git repository. The .git/ directory contains everything Git needs — commit history, branch information, remote connections, and configuration.
.git/ folder is the entire project history. Deleting it means losing every commit, branch, and tracked change permanently.The Four-Stage Git Model
The most important concept in Git. Every file change moves through four stages before it reaches GitHub.
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).
git add main.cpp # add one file
git add . # add all changesStage 3 — Local Repository
A permanent snapshot stored on your machine. The commit creates a unique ID (hash) and stores the snapshot with your message.
git commit -m "Add UART driver"Stage 4 — Remote Repository
Your commits uploaded to GitHub — accessible from anywhere, backed up, and shareable.
git push origin mainCommits
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.
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.
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.
The main branch stays stable. The feature/wifi branch develops independently. Both can advance simultaneously.
# Create and switch to a new branch
git switch -c feature/wifi
# Switch back to main
git switch main
# List all branches
git branchmain. Create a feature branch, develop and test there, then merge into main only after hardware testing passes.Merge & Rebase
Merge
Combines a feature branch back into main. It creates a merge commit that preserves the full history of both branches.
git switch main
git merge feature/wifiRebase
An alternative that replays commits on top of main, creating a cleaner linear history — but it rewrites commit hashes.
git rebase main.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.
.pio/
build/
.vscode/settings.json
*.log
*.tmp
wifi_credentials.h
secrets.hRemote
A remote is a named connection between your local repository and a GitHub repository. The default name is origin.
# Connect local repo to GitHub
git remote add origin https://github.com/user/project.git
# See all remotes
git remote -vPush, 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.
git push origin main # upload to GitHub
git pull origin main # download from GitHub
git clone https://github.com/user/project.git # copy repoStash, Restore, Reset & Revert
Stash — Temporary Drawer
Save unfinished work without committing it. Useful when you need to switch branches mid-task.
git stash # save unfinished work
git stash pop # restore it laterRestore — Undo File Changes
Discard changes to a specific file, restoring it to the last committed state.
git restore main.cppReset — Dangerous Undo
Removes all uncommitted changes permanently. Use with extreme caution.
git reset --hard HEAD # nuclear button — cannot be undonegit 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.
git revert a3f8c1d # safely undo a specific commitTags & SSH Keys
Tags — Permanent Version Markers
Tags mark important milestones — firmware releases, stable versions, deployment points.
git tag -a v1.0.0 -m "First stable firmware release"
git push origin v1.0.0SSH 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).
ssh-keygen -t ed25519 # generate key pair
ssh -T git@github.com # test the connectionCommit Message Rules
Commit messages are communication. They tell your future self and your teammates what changed and why.
- 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
Commands Reference
Daily Commands
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 GitHubBranch Commands
git switch -c feature/wifi # create + switch
git switch main # switch to main
git branch # list branches
git merge feature/wifi # merge into currentHistory Commands
git log --oneline # compact history view
git diff # see unstaged changes
git diff --staged # see staged changesRecovery Commands
git stash # temporarily save work
git stash pop # restore stashed work
git restore <file> # undo file changes
git revert <commit> # safely undo a commitEmbedded Workflow & Summary
Professional Workflow for Every Project
Mental Model Reference
| Concept | Mental Model | Key Command |
|---|---|---|
| Repository | Project folder with history | git init |
| Commit | Save game checkpoint | git commit -m |
| Branch | Alternate timeline | git switch -c |
| Merge | Combine timelines | git merge |
| Remote | GitHub connection | git remote add |
| Push | Laptop → GitHub | git push |
| Pull | GitHub → Laptop | git pull |
| Clone | Copy repository | git clone |
| Stash | Temporary drawer | git stash |
| Tag | Version milestone | git tag -a |
| SSH Key | Secure login credential | ssh-keygen |
- Commit frequently — every feature, fix, or config change gets its own commit.
- Write meaningful commit messages — your future self will thank you.
- Keep
mainstable — 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