Brandon Snell

GIT: Best practices (Pull Request Workflow)

Most teams learn Git the same way. Someone sets up a repository, everyone pushes to main, and it works until the week two people change the same file the night before a competition. Then someone runs a command they found online, a day of work disappears, and the team decides Git is the problem.

The truth of the matter is that Git is not the problem. Pushing straight to main, or worse working directly on main, is. The fix is a short, repeatable loop: create a branch, commit your work to that branch, open a pull request, get it reviewed, and then merge the branch back to main. This article walks through that loop one step at a time and explains why the pull request is the part that matters most.

Why pull requests matter

A pull request (PR) is a proposal: “here is a set of changes, please look at them before they go into main.” That one step does four things that pushing to main cannot.

Someone else reads the code. The person who wrote a change is the person least likely to catch errors in their code or logic. A second reader may catch a wrong CAN ID, an inverted motor, or a command that never ends. There are often simple things that a second set of eyes can catch before spending hours trying to figure out why your change corrupted the entire codebase.

main stays working. main only ever contains code that someone looked at and, ideally, that built and passed its tests. This means that anyone can check out main at any moment and deploy it. On a competition day, that is worth more than any feature.

Checks run before merging, not after. GitHub can build the code and run tests on every PR automatically. A broken build shows up as a red X on the PR, not as a robot that will not deploy in the pit. This next level of automatic checking keeps you working on what matters most, and does not stall your fellow programmers with a failing robot.

You get a record of why. Commit messages, when utilized properly, tell you what changed. A PR tells you why, who agreed to it, and what was discussed. Six months later, when someone asks why the elevator’s current limit is 40 amps, the answer is in the PR that set it.

There is a fifth benefit that matters for teams: PRs teach. A student who reads a mentor’s review comments learns more than one who gets their code silently rewritten. A student who reviews a mentor’s PR learns even more.

Before you start

This walkthrough uses GitHub Desktop, GitHub’s free app for Windows and macOS. Every step also shows the command-line version, if you would rather type.

  1. Download GitHub Desktop from desktop.github.com. It runs on Windows 10 (64-bit) or later and macOS 12 or later. It comes with its own copy of Git, so you do not need to install Git separately unless you want the command line too.
  2. Sign in with your GitHub account. On Windows, go to File > Options > Accounts. On macOS, go to GitHub Desktop > Settings > Accounts.
  3. Clone the repository once. Go to File > Clone Repository, pick it from the GitHub tab, choose where to save it under Local Path, and click Clone. You need write access to the repository to push to it.

The Clone a Repository window in GitHub Desktop, with the team’s robot repository selected

Every new piece of work should start from an up-to-date main. Click Current Branch at the top of the window and choose main, then click Fetch origin. If GitHub has anything new, the button changes to Pull origin, and you should click it.

The GitHub Desktop toolbar on main, with the Pull origin button

Skipping this step is a common cause of merge conflicts. If you branch from a week-old copy of main, your PR has to catch up with a week of everyone else’s work.

On the command line:

git clone https://github.com/your-team/robot-2027.git
cd robot-2027
git switch main
git pull

Step 1: Make a branch

A branch is your own line of work, and nothing you do on it touches main until the PR is merged.

With main selected, click Current Branch, then New Branch. Type a name and make sure it is based on main, then click Create Branch.

The Create a Branch window, naming the new branch intake-current-limit based on main

Name the branch after the work you are doing. A name like intake-current-limit tells the team what the branch is for, where bobs-branch tells them nothing.

One branch should hold one change. If you find a second, unrelated problem while you work, note it and fix it on its own branch later, because small PRs get reviewed quickly and carefully, while large ones tend to get skimmed.

On the command line:

git switch -c intake-current-limit

Step 2: Commit as you go

Make your change in your editor. Repository > Open in Visual Studio Code (or whichever editor you have set) opens the project for you.

Then come back to GitHub Desktop. The Changes tab lists every file you have touched, and clicking a file shows exactly which lines changed. Read the changes every time, because this is where you catch the debug print you forgot to remove and the file you did not mean to change.

The Changes tab in GitHub Desktop, showing the intake current limit changing from 40 to 30

Each file has a checkbox, and only checked files go into the commit, so uncheck anything that does not belong, like build output, logs, or someone’s editor settings.

At the bottom left, write a Summary of the change, add more detail in Description if it needs it, and click Commit to intake-current-limit.

The Summary and Description fields filled in, above the Commit to intake-current-limit button

A good summary finishes the sentence “This commit will…”. Say what changed and, if it is not obvious, why it changed. A message like “Fixed stuff” helps no one, including you in three weeks.

Commit often, because a branch with five small commits is easier to review and easier to undo than one with a single commit called “all the intake changes.”

On the command line:

git status
git diff
git add src/main/java/frc/robot/subsystems/Intake.java
git commit -m "Lower intake current limit to 30A to stop breaker trips"

Add files by name rather than git add . until you trust your .gitignore.

Step 3: Push the branch

Your commits only exist on your laptop until you push them.

The first time, click Publish branch in the toolbar. That creates the branch on GitHub. After that, the same button reads Push origin, and you click it whenever you have new commits to send.

The GitHub Desktop toolbar showing Publish branch

On the command line:

git push -u origin intake-current-limit

The -u tells Git to remember where this branch lives on GitHub, so after the first push you can just type git push.

Step 4: Open the pull request

Once the branch is published, GitHub Desktop offers Preview Pull Request. Click it to see every change your PR will contain, compared with main. Check that the base branch is main, then click Create Pull Request. GitHub Desktop opens the pull request page on GitHub in your browser.

The Preview Pull Request window in GitHub Desktop, comparing intake-current-limit with main

From here on, everything happens on github.com, whichever way you pushed. If you used the command line, go to the repository on GitHub and click Compare & pull request on the banner that appears after a push.

The title and description are where PRs often fall short. A reviewer should be able to understand the change without asking you.

The title should say what the PR does, for example “Lower intake current limit to stop breaker trips,” rather than a short label like “Intake.”

The description answers three questions:

  1. What changed? One or two sentences.
  2. Why? The problem it fixes or the goal it reaches.
  3. How was it tested? In simulation, on the robot, or not yet. Be honest. Saying “Not tested on the robot yet” gives the reviewer useful information, and saying nothing leaves them guessing.

For example:

Lowers the intake roller current limit from 40A to 30A.

During practice on Saturday the intake breaker tripped three times while
holding a game piece. Logs show the roller stalling at about 38A for several
seconds.

Tested on the practice robot: 20 intake cycles with no trips, and pickup speed
looks the same. Not yet tested with a full battery drain.

If the work is not finished but you want early feedback, open it as a draft pull request: use the arrow next to Create pull request, choose Create draft pull request, then click Draft pull request. Draft PRs cannot be merged by accident, and they tell reviewers to look at the direction of the work rather than the final details.

Finally, ask for a review by adding someone under Reviewers in the sidebar. If you open a PR and wait for someone to notice it, it can sit for a week.

The new pull request form on GitHub, with a title, a description, and a reviewer added

Step 5: Review, and respond to review

Reviewing happens on GitHub, because GitHub Desktop cannot leave comments on a PR.

When you review someone else’s PR, open the Files changed tab and read every line. Leave comments on specific lines. When you finish, click Submit review. In the Finish your review box, submit as one of three options: Comment, Approve, or Request changes. (Approve and Request changes are disabled if you are the author of the PR.)

The Finish your review box on GitHub, with Comment, Approve and Request changes

Good review comments are specific and kind. A comment like “This will run every loop. Should it only run once when the command starts?” gives the author something to work with, where “This is wrong” does not. Ask questions when you are not sure, because reviewers miss things too.

If you want to run someone’s PR on the robot, GitHub Desktop can open it: click Current Branch, then the Pull Requests tab, and pick the PR.

When you get review comments on your own PR, fix them on the same branch. Make the change, commit it in GitHub Desktop, and click Push origin. The PR updates automatically, and there is no need to open a new one. Reply to each comment so the reviewer knows what you did, and resolve the conversation once it is handled.

If you disagree with a comment, say so and explain why. A review is a conversation between teammates, and both sides are trying to make the code better.

On the command line:

git add src/main/java/frc/robot/subsystems/Intake.java src/main/java/frc/robot/Constants.java
git commit -m "Move current limit to Constants"
git push

Step 6: Merge and clean up

Once the PR is approved and its checks pass, merge it on GitHub. The merge button has three options:

  • Create a merge commit keeps every commit from the branch, plus one commit that joins it to main.
  • Squash and merge combines the branch into a single commit on main. This keeps history clean, and it is a good default for most teams.
  • Rebase and merge replays each commit onto main without a merge commit.

Pick one as a team and use it every time. After merging, click Delete branch on the PR page.

The merge box on GitHub with Squash and merge selected

Then tidy up your own copy in GitHub Desktop:

  1. Click Current Branch, choose main, then Fetch origin and Pull origin so your main has the merged work.
  2. Delete your old branch: choose it under Current Branch, then go to Branch > Delete… (Ctrl+Shift+D on Windows, Shift+Command+D on macOS).

Then start the loop again for the next change.

On the command line:

git switch main
git pull
git branch -d intake-current-limit

If you squashed, Git may refuse with “the branch is not fully merged.” Squashing created a new commit on main, so Git does not recognize your branch’s commits as merged. Once you have confirmed the PR merged on GitHub, git branch -D intake-current-limit (capital D) deletes it anyway.

If main moved while you worked

Sometimes another PR merges before yours and touches the same lines. GitHub then reports that the branch has conflicts. Bring the new main into your branch:

  1. Update main: choose it under Current Branch, then Fetch origin and Pull origin.
  2. Switch back to your branch under Current Branch.
  3. In the same menu, click Choose a branch to merge into intake-current-limit, pick main, and click Merge main into intake-current-limit.

The merge window in GitHub Desktop, merging main into intake-current-limit

If there are no conflicts, click Push origin and you are done.

If there are, GitHub Desktop warns you above the merge button and lists the conflicted files, with an option to open each one in your editor. Find the <<<<<<< and >>>>>>> markers and edit each section so it is what the code should actually be, which is often a bit of both. Remove the markers and save. When every file is resolved, finish the merge from the same window and click Push origin.

GitHub Desktop listing a conflicted file, with a button to open it in the editor

Conflicts are a normal part of working on a team, and they do not mean you did something wrong. They are much smaller when branches are short-lived and everyone pulls main before starting.

On the command line:

git switch intake-current-limit
git fetch origin
git merge origin/main

Fix the conflicted files, then finish the merge:

git add src/main/java/frc/robot/subsystems/Intake.java
git commit --no-edit
git push

git fetch downloads the latest main from GitHub without changing your files, and git merge brings it into your branch. (You may see git pull origin main suggested instead. Depending on how Git is set up, it may refuse until you tell it whether to merge or rebase. The two-step version works either way.) --no-edit keeps Git’s default merge message instead of opening a text editor.

Optional: start from an issue

GitHub Issues give the loop a starting point. An issue is a to-do item with a discussion attached: “Intake breaker trips when holding a game piece.” Anyone can open one, including the drive team, and it records the problem before anyone starts on a fix.

The workflow becomes: open an issue, make a branch for it, open a PR that fixes it. In GitHub Desktop, Repository > Create Issue on GitHub opens a new issue in your browser. If the PR description includes Closes #42, GitHub links the two, and merging the PR closes issue 42 automatically. Fixes and Resolves work the same way. This only works when the PR targets the repository’s default branch, which is usually main.

For a team, the issue list becomes the build-season backlog, and new programmers can pick up small, well-described issues without having to ask what to work on.

Common mistakes

Committing to main by accident. Glance at Current Branch before you click commit. If you have already committed to main but have not pushed, click Undo at the bottom of the Changes tab to take the commit back. Then create your branch and choose Bring my changes to the new branch when GitHub Desktop asks. On the command line, git status shows your branch. If you have already committed to main, make a branch from where you are with git switch -c my-fix, then ask someone to help you reset main.

Huge PRs. If a PR changes 40 files, nobody is going to review it properly. Break it into smaller PRs.

Approving without reading. An approval says “I read this and I think it is right.” If you did not read it, do not approve it.

Force-pushing over shared work. git push --force rewrites history on GitHub. On your own branch it is sometimes the right tool. On main or someone else’s branch, it erases their work. Turn on branch protection for main in the repository settings so that changes must come through a PR and nobody can force-push to it. (On the free plan, branch protection only works on public repositories. Protecting a private repository needs a paid plan such as GitHub Team.)

Keeping secrets in the repository. Passwords and API keys do not belong in git. Once something is committed, deleting it in a later commit does not remove it from the history.

Final Thoughts

If I could get a team to adopt one habit, it would be this loop. Start from an up-to-date main in GitHub Desktop, make a branch for each change, commit as you go, and open a pull request before anything reaches main. Take the time to write a title and a description that explain what changed, why it changed, and how it was tested. If it has not been tested on the robot yet, say so.

Then get it reviewed. A second set of eyes can catch an inverted motor before it shows up in the pit, and a student who reads a mentor’s comments, or reviews a mentor’s PR, will learn more than one whose code gets silently rewritten. When the checks pass, squash and merge is a good default for most teams. Pull main, delete the old branch, and start the next change the same way. If main moved while you were working, merge it into your branch and work through the conflicts. They are normal.

Do this consistently and main stays in a state you can deploy on competition day, which is worth more than any one feature. As mentors, it is our job to instill these habits early, because the pull request protects the robot and teaches the student at the same time.