Overview
Git is a distributed version control system that tracks changes to your code over time. GitHub is a cloud-based hosting platform for Git repositories that enables team collaboration. Together, they form the backbone of modern software development and are essential for managing code in team projects like the mecanum robot.Version Control
Track changes, revert mistakes, and maintain code history
Collaboration
Work simultaneously with teammates without overwriting each other’s code
Why Use Git?
Without version control:- Undo mistakes: Revert to previous working versions
- Track changes: See who changed what, when, and why
- Branching: Work on features independently without breaking main code
- Backup: Cloud storage on GitHub prevents data loss
- Collaboration: Merge code from multiple teammates automatically
Installation
Git
- Windows
- macOS
- Linux (Ubuntu/Debian)
- Download Git from git-scm.com/downloads
- Run installer with default settings
-
Important options:
- ✓ Use Git from the command line and 3rd-party software
- ✓ Use bundled OpenSSH
- ✓ Checkout Windows-style, commit Unix-style (recommended)
-
Verify installation:
Configure Git
Set your identity (required for commits):Use the same email you’ll use for GitHub to link commits to your account
GitHub Account Setup
1
Create GitHub Account
Visit github.com and sign upRecommendations:
- Use RMIT email for student benefits
- Choose professional username (e.g.,
john-smith-rmit, notxXcoder123Xx)
2
Enable Student Benefits
Visit education.github.com/studentsApply for GitHub Student Developer Pack (free):
- Unlimited private repositories
- GitHub Copilot (AI code assistant)
- Free cloud credits and premium tools
3
Set Up SSH Key (Recommended)
SSH keys allow pushing/pulling without entering password each timeAdd SSH key to GitHub:
- GitHub → Settings → SSH and GPG keys
- Click New SSH key
- Paste key, add title (e.g., “My Laptop”)
- Click Add SSH key
Basic Git Workflow
Creating a Repository
- Option 1: Create on GitHub (Recommended)
- Option 2: Start Locally
- Go to GitHub → Click New (green button)
- Repository name:
mecanum-robot-firmware - Description: “ESP32 firmware for EEET2610 mecanum robot”
- Visibility: Private (for coursework)
- ✓ Add README file
- Add .gitignore: PlatformIO
- License: MIT (optional)
- Click Create repository
Daily Git Commands
Branching Strategy
Branches allow working on features independently without affecting the main codebase.Creating Branches
Recommended Team Workflow
Merging Branches
Pull Requests (PRs)
Pull Requests are the professional way to merge code in team projects.1
Push Feature Branch to GitHub
2
Create Pull Request on GitHub
- Go to repository on GitHub
- Click Pull requests → New pull request
- Base:
main← Compare:feature/lidar-integration - Add title: “Add LiDAR sensor integration”
- Add description:
- Click Create pull request
3
Code Review
Teammates review code:
- Leave comments on specific lines
- Request changes if needed
- Approve when satisfied
- Make changes in feature branch
- Push updates (PR auto-updates)
4
Merge Pull Request
Once approved:
- Click Merge pull request
- Confirm merge
- ✓ Delete branch (cleanup)
5
Update Local Repository
.gitignore File
Prevent unnecessary files from being committed:.gitignore
Common Scenarios
Scenario 1: Undo Last Commit (Not Pushed)
Scenario 2: Discard Uncommitted Changes
Scenario 3: View Changes Before Committing
Scenario 4: Stash Changes Temporarily
Scenario 5: Sync Fork with Original Repository
Team Collaboration Best Practices
Commit Often
- Commit small, logical changes frequently
- Don’t wait until end of day
- Each commit should be buildable
- Write descriptive commit messages
Pull Before Push
- Always
git pullbefore starting work - Resolve conflicts locally before pushing
- Prevents overwriting teammates’ code
- Run tests after pulling
Use Branches
- Never commit directly to
main - Create feature branches for new work
- Delete branches after merging
- Keep
mainalways deployable
Code Reviews
- Review teammates’ pull requests
- Be constructive and respectful
- Look for bugs, style issues, logic errors
- Approve only when confident in changes
Write Good Commits
Format:First line: summary (50 chars)
Body: details (optional)
Protect Main Branch
GitHub Settings → Branches:
- ✓ Require pull request reviews
- ✓ Require status checks to pass
- ✓ Dismiss stale reviews
- ✓ Require conversation resolution
GitHub Features for Teams
Issues
Track bugs, features, and tasks:bug, feature, enhancement, documentation
Projects (Kanban Board)
Organize work visually:Wiki
Document project knowledge:- Setup instructions
- Hardware wiring diagrams
- Troubleshooting guides
- Meeting notes
Releases
Tag stable versions:Git Cheat Sheet
Troubleshooting
Permission denied (publickey) error
Permission denied (publickey) error
Symptoms:
git@github.com: Permission denied (publickey)Solutions:-
Verify SSH key added to GitHub:
- GitHub → Settings → SSH and GPG keys
-
Test SSH connection:
-
If still failing, use HTTPS instead:
- Regenerate SSH key and add to GitHub
Merge conflict
Merge conflict
Symptoms:
CONFLICT (content): Merge conflict in src/main.cppSolutions:- Open conflicted file in editor
-
Look for conflict markers:
- Edit file to choose correct version (remove markers)
-
Stage and commit resolved file:
Accidentally committed to main instead of feature branch
Accidentally committed to main instead of feature branch
Solutions:
-
Create feature branch with current changes:
-
Reset main to previous commit:
-
Switch to feature branch:
- Now commit is on feature branch only
Push rejected: non-fast-forward
Push rejected: non-fast-forward
Symptoms:
! [rejected] main -> main (non-fast-forward)Cause: Remote has commits you don’t have locallySolutions:-
Pull first, then push:
-
If conflicts occur, resolve and continue:
Large file error: file exceeds 100 MB
Large file error: file exceeds 100 MB
Symptoms:
remote: error: File data.csv exceeds 100 MBSolutions:-
Remove file from commit:
-
Add to .gitignore:
-
Use Git LFS for large files (optional):
- Or store large files externally (Google Drive, OneDrive)
Learning Resources
Interactive Git Tutorial
Visual, hands-on Git tutorial (highly recommended!)
GitHub Skills
Official GitHub interactive courses
Pro Git Book
Complete Git reference (free online)
Git Cheat Sheet PDF
Printable command reference
Next Steps
Team Management
Set up team collaboration workflow
VSCode & PlatformIO
Integrate Git with your development environment
Project Structure
Organize code for version control
GitHub Actions
Advanced: Automate testing and builds (CI/CD)
- Auto-run tests on every commit
- Deploy documentation automatically
References
- Git Documentation
- GitHub Docs
- Atlassian Git Tutorials
- Oh Shit, Git!?! - Fix common Git mistakes
- GitHub Student Developer Pack