Table of Contents
KEY TAKEAWAYS
- Git tracks changes to source code, enabling collaboration, branching, and reverting to previous versions
- Core workflow:
git add(stage),git commit(save),git push(share),git pull(update) - Branching allows parallel development of features without affecting the main codebase
- Version control is essential for embedded projects — track firmware versions, hardware revisions, and configuration changes
Why Version Control?
Imagine you have a working firmware. You make some changes, and suddenly it stops working. Now you want to go back to the version that worked, but you have already overwritten the files. This is the problem version control solves.Git is the most widely used version control system. It tracks every change you make to your code, lets you revert to any previous version, and makes collaborating with others seamless.Even if you work alone, Git is essential because:- You can undo mistakes and go back to any previous state
- You can experiment in branches without affecting working code
- You have a complete history of what changed, when, and why
- You can work on multiple features simultaneously
Installing Git
Windows: Download fromgit-scm.com and install. Use Git Bash or integrate with your IDE.Linux:sudo apt install git # Debian/Ubuntu sudo yum install git # CentOS/RHELmacOS:
brew install git # Using HomebrewAfter installation, configure your identity:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
Core Concepts
Repository
A repository (repo) is a folder tracked by Git. It contains your project files plus a hidden.git folder that stores the complete history.Commit
A commit is a snapshot of your project at a specific point in time. Each commit has a unique ID, a message describing the change, and a pointer to the previous commit.Branch
A branch is an independent line of development. The default branch is calledmain (or master). You create branches to work on features without affecting the main code.Working Directory, Staging Area, Repository
Working Directory Staging Area Local Repository
(your files) (index) (commit history)
| | |
|--- git add ----->| |
| |--- git commit -->|
| | |
|<--------- git checkout ------------|Essential Git Commands
Starting a Project
# Create a new repository mkdir my-firmware cd my-firmware git init # Or clone an existing repository git clone https://github.com/user/project.git
Daily Workflow
# Check what has changed git status # See the actual changes git diff # Stage specific files for commit git add main.c uart.c uart.h # Or stage all changes git add . # Commit with a descriptive message git commit -m "Add UART driver with TX and RX support" # View commit history git log --oneline
Branching
# Create and switch to a new branch git checkout -b feature/spi-driver # Work on your feature, commit changes... git add spi.c spi.h git commit -m "Implement SPI driver for sensor communication" # Switch back to main branch git checkout main # Merge the feature branch into main git merge feature/spi-driver # Delete the branch after merging git branch -d feature/spi-driver
Working with Remote Repositories (GitHub/GitLab)
# Add a remote repository git remote add origin https://github.com/user/my-firmware.git # Push your code to the remote git push -u origin main # Pull latest changes from the remote git pull origin main
A .gitignore for Embedded Projects
Not everything should be tracked by Git. Create a.gitignore file to exclude generated files:# Build output build/ *.o *.elf *.hex *.bin *.map *.lst # IDE files .vscode/ *.swp *.swo .idea/ # Dependency directories node_modules/ # OS files .DS_Store Thumbs.db # Debug files *.log *.dmp
Writing Good Commit Messages
Good commit messages make your history useful. Follow this pattern:# Short, imperative summary (under 72 characters) Add I2C driver for BME280 sensor # Why (not what - the diff shows what) Fix ADC overflow when reading channel 7 at high sample rates # Bad examples: "fixed stuff" "update" "work in progress" "asdfghj"
Common Scenarios
Undo the Last Commit (Keep Changes)
git reset --soft HEAD~1
Discard All Local Changes
git checkout -- . # Or for untracked files too: git clean -fd
See Who Changed a Line
git blame main.c
Compare Two Versions
git diff v1.0..v2.0
Tag a Release
git tag -a v1.0 -m "First stable release" git push origin v1.0
Git Workflow for Embedded Teams
A common workflow for firmware projects:main (stable, tested)
|
+-- develop (integration branch)
|
+-- feature/uart-driver
+-- feature/ota-update
+-- bugfix/adc-overflowmainalways contains tested, release-ready firmwaredevelopis where features are integrated and tested together- Feature branches are created from
developfor each task - When a feature is complete, it is merged back into
develop - When
developis stable, it is merged intomainand tagged with a version number
Summary
Git is a fundamental tool for any embedded developer. Even for personal projects, the ability to track changes, revert mistakes, and work on features in isolation makes development faster and safer. Start simple withinit, add, commit, and push. As your projects grow, adopt branching and tagging to manage releases and collaborate effectively.
Vivek Bhageria — Lead Firmware R&D Engineer, 12+ years. Ex-Bosch (automotive powertrain), MusicTribe (real-time audio), medical devices. M.Tech BITS Pilani. I write at NerdyElectronics — practical, register-level embedded systems for engineers who want to understand what’s actually happening under the hood.






