Lesson 4.2: Git & GitHub Team Workflow
π― What Youβll Learn
By the end of this lesson you will be able to:
- Explain why FRC teams use branches instead of committing directly to main
- Describe the feature branch workflow used by most FRC teams
- Create a branch, make commits, and push to GitHub
- Explain what a pull request is and why code review matters
- Identify and resolve a simple merge conflict
Why Branches Matter
In Unit 0 you learned to clone the repo and make commits. But on a real team, multiple programmers work on the code at the same time. If everyone commits directly to the main branch, chaos ensues:
- Alice changes the intake speed while Bob rewrites the intake subsystem
- Their changes conflict, and the code breaks
- Nobody knows whose change caused the problem
- The robot doesnβt work at practice, and the team loses valuable testing time
Branches solve this by giving each person (or each feature) their own copy of the code to work on. When the work is done and tested, it gets merged back into main through a pull request with code review.
The Feature Branch Workflow
Most FRC teams use a simple workflow called feature branching:
main βββββββββββββββββββββββββββββββββββββββββββββββββ \ / feature/intake-speed ββββββββ (merged via PR) \ / feature/auto-two-note βββββββββββββββ (merged via PR)The Rules
mainis always deployable β the code onmainshould always compile and work on the robot. Never commit broken code tomain.- Create a branch for each change β whether itβs a bug fix, a new feature, or a tuning adjustment.
- Name branches descriptively β
feature/intake-speed,fix/shooter-timeout,tune/auto-timing. The name should tell teammates what the branch is about. - Merge through pull requests β never push directly to
main. Always create a PR so someone can review your changes.
Branch Naming Conventions
| Prefix | When to Use | Example |
|---|---|---|
feature/ | Adding new functionality | feature/auto-three-note |
fix/ | Fixing a bug | fix/intake-not-retracting |
tune/ | Adjusting constants or parameters | tune/shooter-rpm |
refactor/ | Reorganizing code without changing behavior | refactor/constants-cleanup |
Creating and Using Branches
Hereβs the step-by-step workflow for making a change:
Step 1: Start from an Updated Main
git checkout main # Switch to main branchgit pull origin main # Get the latest code from GitHubAlways start from the latest main. If you branch from an old version, youβll have more merge conflicts later.
Step 2: Create Your Branch
git checkout -b feature/intake-speedThis creates a new branch called feature/intake-speed and switches to it. Youβre now working on your own copy of the code.
Step 3: Make Your Changes and Commit
# Edit files in your IDE...git add . # Stage all changesgit commit -m "Increase intake roller speed to 0.7" # Commit with a clear messageCommit messages matter. Write messages that explain what you changed and why. Your teammates (and future you) will thank you.
| Bad Message | Good Message |
|---|---|
fixed stuff | Fix intake not retracting after toggle off |
changes | Increase shooter RPM from 3000 to 3500 for longer shots |
asdf | Add two-note auto routine for left starting position |
Step 4: Push to GitHub
git push origin feature/intake-speedThis uploads your branch to GitHub. Your code is now backed up and visible to teammates.
Step 5: Create a Pull Request
On GitHub, youβll see a banner saying βfeature/intake-speed had recent pushes.β Click βCompare & pull requestβ to create a PR.
Why should you run 'git pull origin main' before creating a new branch?
Pull Requests and Code Review
A pull request (PR) is a request to merge your branch into main. Itβs also a conversation β your teammates review your changes, ask questions, and suggest improvements before the code is merged.
What Makes a Good PR
| Element | What to Include |
|---|---|
| Title | Clear summary: βIncrease intake speed to 0.7 for faster pickupβ |
| Description | What you changed, why, and how to test it |
| Small scope | One logical change per PR β donβt mix unrelated changes |
| Tests | βI tested this by deploying to the robot and running intake 10 timesβ |
The Code Review Process
- You create the PR on GitHub
- Request a reviewer β tag a teammate or your programming lead
- The reviewer reads your changes β GitHub shows a diff (what you added/removed)
- The reviewer leaves comments β questions, suggestions, or approval
- You address feedback β make additional commits to your branch if needed
- The reviewer approves β they click βApproveβ
- You merge the PR β click βMerge pull requestβ on GitHub
- Delete the branch β GitHub offers to delete the branch after merging. Do it β keeps things clean.
Why Code Review Matters for FRC
Code review isnβt just a formality. On an FRC team, it catches:
- Safety issues β βThis motor speed is too high, it could damage the mechanismβ
- Logic bugs β βThis auto routine turns left when it should turn rightβ
- Constants mistakes β βYou used CAN ID 31 but the intake left motor is CAN ID 31β
- Style issues β βThis should be a constant in Constants.java, not a magic numberβ
Even a quick 5-minute review by a teammate can catch bugs that would waste hours of testing time.
Handling Merge Conflicts
A merge conflict happens when two people change the same lines in the same file. Git canβt automatically decide which change to keep, so it asks you to resolve it manually.
When Conflicts Happen
main: intake speed = 0.5Alice: intake speed = 0.7 (on feature/faster-intake)Bob: intake speed = 0.6 (on feature/tune-intake)If Alice merges first, Bobβs PR will have a conflict on the intake speed line. Git doesnβt know if the answer should be 0.6, 0.7, or something else.
What a Conflict Looks Like
When you pull or merge and thereβs a conflict, Git marks the file:
<<<<<<< HEAD private static final double INTAKE_SPEED = 0.7; // Alice's change (already in main)======= private static final double INTAKE_SPEED = 0.6; // Bob's change (on his branch)>>>>>>> feature/tune-intakeHow to Resolve
- Open the conflicted file in your IDE (VS Code highlights conflicts with colors)
- Choose which change to keep β or combine them if both are needed
- Remove the conflict markers (
<<<<<<<,=======,>>>>>>>) - Save, commit, and push
// After resolving β Bob decides Alice's value is better: private static final double INTAKE_SPEED = 0.7;-
Before starting:
git checkout mainthengit pull origin mainβ switch to main and get the latest code from GitHub. -
Create a branch:
git checkout -b feature/descriptive-nameβ creates a new branch with a descriptive name using the appropriate prefix (feature/, fix/, tune/). -
Getting into main: Make changes β
git add .βgit commit -m "Clear message"βgit push origin feature/descriptive-nameβ Create a Pull Request on GitHub β Request code review β Address feedback β Reviewer approves β Merge the PR β Delete the branch. -
Merge conflict: Open the conflicted file in your IDE β find the conflict markers (
<<<<<<<,=======,>>>>>>>) β choose which change to keep (or combine them) β remove the markers β save βgit add .βgit commitβgit push.
Git Commands Quick Reference
| Command | What It Does |
|---|---|
git checkout main | Switch to the main branch |
git pull origin main | Download latest changes from GitHub |
git checkout -b branch-name | Create and switch to a new branch |
git add . | Stage all changed files for commit |
git commit -m "message" | Save staged changes with a description |
git push origin branch-name | Upload your branch to GitHub |
git status | See which files are changed/staged |
git log --oneline | See recent commit history |
git diff | See what youβve changed but not yet staged |
Key Terms
π All terms below are also in the full glossary for quick reference.
| Term | Definition |
|---|---|
| Branch | A separate line of development in Git, allowing you to work on changes without affecting the main codebase |
| Feature Branch | A branch created for a specific change (feature, fix, or tune), named descriptively with a prefix |
| Pull Request (PR) | A GitHub request to merge a branch into main, including a description and code review process |
| Code Review | The process of a teammate reading your changes, leaving feedback, and approving before merge |
| Merge Conflict | A situation where two branches change the same lines, requiring manual resolution |
| Main Branch | The primary branch that should always contain working, deployable code |
Whatβs Next?
You now understand the Git workflow your team uses to collaborate safely on robot code. Branches keep everyoneβs work separate, pull requests ensure quality through review, and merge conflicts are manageable with the right approach.
In Activity 4.3: Create a Pull Request, youβll practice this workflow hands-on β creating a branch, making a safe edit, pushing to GitHub, and opening your first PR with a code review request.
In Activity 4.3: Create a Pull Request, youβll practice this workflow hands-on β creating a branch, making a safe edit, pushing to GitHub, and opening your first PR with a code review request.