Git และการทำงานร่วมกันแบบมีเวอร์ชัน

Commits, branches, pull requests and managing project code

Last updated:

Overview

A drone project is full of files that keep changing: companion-computer code, analysis scripts, flight-controller parameter files and mission plans. Save them as final_v3_fixed.py and the team soon cannot say which code flew in yesterday's test. Version control solves this by recording every change, allowing roll-back, and letting several people work on the same code without overwriting each other. Git is by far the most widely used system, and the book Pro Git is free on the Git website.

Commits and Git's four areas

A repository (repo) is a project folder together with its full history. A commit is a snapshot of the whole project at one moment, with author, time, message and a link to the previous commit. Each commit has an ID computed from its content (a hash), by default 40 hexadecimal digits, usually quoted by its first 7. Change a single byte and the ID changes, so history cannot be quietly rewritten.

Files move through four areas:

  1. Working tree, where you edit files.
  2. Staging area, where git add selects which changes go into the next commit.
  3. Local repository, where git commit records them.
  4. Remote, such as GitHub, updated with git push; teammates' work comes down with git pull.

A good commit is small, does one thing, and says what changed. Conventional Commits messages such as feat: add gutter-following route or fix: treat 15% battery as LOW make history quick to scan.

Branches, merges and pull requests

A branch is a separate line of work split from the main line, like editing a copy of a draft without touching the original. When the work is done it is merged back. If two people changed the same lines differently, Git stops and reports a merge conflict for a human to resolve: Git marks the clashing sections in the file, you choose or combine the content, remove the markers and commit.

GitHub flow is a simple process for small teams:

  1. The main branch must always run.
  2. Every new piece of work gets a branch named for the task, such as feat/battery-check.
  3. Commit and push to the remote often.
  4. Open a pull request to ask for the merge; at least one teammate reviews it.
  5. Once tests and review pass, merge into main and delete the branch.

Any version taken to a flight test should get a tag, for example git tag -a flight-test-2026-10-14 -m "SITL passed", with the tag name written in the test log. When something goes wrong in the air, the team can see at once exactly which code and parameters flew.

What to check in a pull request

Review is not fault-finding; it is a second pair of eyes before code goes flying. A reviewer should check at least five things:

  1. Does it do what it claims? Compare the pull request description with the actual changes.
  2. Do the tests pass? Run the existing tests, and for mission code require a passing SITL run first.
  3. Are units and limits right? Metres versus centimetres, battery percentages, maximum altitude.
  4. Are there secrets or files that do not belong in the repo?
  5. Can someone else understand it? Meaningful names and clear commit messages.

Flight-controller parameter changes should go through pull requests just like code, because one wrong value, such as a battery failsafe threshold, can bring an aircraft down. With the parameter file in Git, git diff shows at once which values changed since the last version that flew safely.

Undoing work safely

  • git restore file discards uncommitted edits to that file.
  • git revert ID creates a new commit that reverses an earlier one, keeping history intact. Use it for work already pushed.
  • git reset moves the branch pointer back. It is fine for work that exists only on your machine, but on work others have pulled it makes the team's histories disagree.

What belongs in the repo

KeepLeave out
Code, scripts and testsPasswords, API keys, .env files
Parameter files exported from the ground station.venv folders and generated files
Mission plans, documentation, READMELarge flight logs, images and video
Dependency lists such as requirements.txtLarge AI model files (record the file name and hash instead)

A .gitignore file tells Git what not to track, and it should exist from the first commit. If a secret has reached the remote, revoke or rotate the secret first, because history and other people's clones still hold it. Cleaning the history afterwards is a secondary step.

Example: a repo bloated by model files

Assume the team commits a 45 MB detection model and retrains it 12 times over the semester. Each version of the weights differs almost everywhere and compresses poorly (assumed to be nearly incompressible).

  1. Every version stays in history, even if the file is deleted in a later commit.
  2. History grows by roughly 45 × 12 = 540 MB.
  3. Every new member downloads all of it on each clone.

A better approach is to keep model files in agreed storage, such as a departmental drive or a large-file storage extension that works with Git, and record the file name and its SHA-256 hash in the repo. The repo barely grows, yet you can still prove which model flew in which test.

Common pitfalls

  • Working directly on main, so people's work collides and main stops running.
  • Huge commits mixing several changes, which cannot be undone selectively.
  • Commit messages like "update".
  • Committing a secret and assuming a later delete is enough.
  • Using git reset or force-push on a branch others use.
  • Not tagging flown versions, so test results cannot be compared.
  • Not pulling before starting work, letting conflicts pile up.

Continue in the lessons

Key references

  1. Chacon, S., & Straub, B. (2014). Pro Git (2nd ed.). Apress. link
  2. GitHub. GitHub flow. GitHub Docs. link
  3. Conventional Commits. Conventional Commits 1.0.0. link
  4. GitHub. Removing sensitive data from a repository. GitHub Docs. link
  5. OWASP Foundation. Secrets management cheat sheet. OWASP Cheat Sheet Series. link

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). Git และการทำงานร่วมกันแบบมีเวอร์ชัน. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/new/prog-git-practice/