26  GitHub and Remote Collaboration

Class Objectives
  1. Understand remote repositories and the role of GitHub as a central “source of truth.”
  2. Set up GitHub authentication directly in the Antigravity IDE (no terminal setup required).
  3. Master the three core Git actions: Commit, Push, and Pull.
  4. Use the IDE’s built-in Source Control panel to review, stage, commit, and sync changes.
  5. Write effective .gitignore files to prevent AI agents from tracking temporary files or large biological datasets.

26.1 What is GitHub and Why Remotes?

In previous chapters, we focused on local Git—managing version control on your own machine. While this tracks history, it doesn’t allow you to share your work with collaborators, back up your code online, or synchronize your progress across different computers (e.g., your laptop and a lab desktop).

To collaborate and sync, we use a remote repository (or simply a “remote”). A remote is a version of your repository hosted on the internet. GitHub is a cloud-based hosting service for Git repositories, acting as the “single source of truth” for a project.

By default, when you link your local repository to a remote repository on GitHub, Git assigns it the default nickname origin.

Setting Up GitHub in the Antigravity IDE

For security reasons, GitHub requires secure authentication. Rather than using complex command-line steps to generate SSH key pairs manually, the Antigravity IDE manages authentication for you in a few clicks. Simply log in using the IDE’s built-in Accounts menu or search for “Sign in to GitHub” in the Command Palette.

26.2 Understanding the Core Concepts: Commit, Push, and Pull

When you work on your assignments or research projects, you will write code and ask AI agents to make edits. Git keeps track of these changes through three core concepts:

graph LR
    WD["Working Directory"] -- "Commit (Save Snapshot)" --> LR["Local Repository"]
    LR -- "Push (Upload)" --> GH["GitHub (Remote)"]
    GH -- "Pull (Sync & Merge)" --> WD
    
    style WD fill:#f9f,stroke:#333,stroke-width:2px
    style LR fill:#bbf,stroke:#333,stroke-width:2px
    style GH fill:#dfd,stroke:#333,stroke-width:2px

  • Commit (Local Snapshot): Saves a snapshot of your files at a specific point in time only on your local computer. Think of it like taking a photo of your project to lock in your progress. Committing does not upload anything to the internet.
  • Push (Upload): Uploads your local commits (snapshots) to the remote repository on GitHub. This backs up your progress to the cloud so you never lose your work.
  • Pull (Download & Sync): Downloads the latest commits from the remote repository on GitHub and merges them into your local files. This is essential when working across multiple computers.
The Golden Rule of Multi-Computer Sync

If you work on both a school desktop and a personal laptop, GitHub acts as the bridge:

  1. Always Pull First: The very first thing you must do when starting a work session is run a Pull. This ensures any progress you made on your other computer is merged into your active workspace.
  2. Commit and Push when Done: Before closing your computer, compile your code, verify it works, and then Push your changes to GitHub to save your progress.

26.3 Everyday Git via the Source Control Sidebar

Instead of typing Git commands in the terminal, you can perform all everyday Git tasks using the Source Control panel (the sidebar icon displaying three nodes connected by a branch, or via the shortcut Cmd + Shift + G / Ctrl + Shift + G).

When you ask the AI assistant to write a function or update a plot, the Source Control sidebar lists all modified files under Changes.

  • Click on any modified file to open a side-by-side Diff view.
  • Red lines (-) represent code deleted.
  • Green lines (+) represent code added by the AI.
  • Best Practice: Always review the diff to audit the AI’s changes before saving!
  • Click the + (Plus) icon next to a file name (or next to “Changes”) to stage the files you want to save.
  • Type a concise, descriptive message in the text box (e.g., "Add species abundance plot").
  • Click the Commit button (or press Cmd + Enter / Ctrl + Enter).
  • Once committed, a button labeled Sync Changes will appear. Clicking it will automatically execute a Pull to get any remote changes, followed by a Push to upload your commits.
  • Alternatively, you can click the ... (More Actions) menu at the top of the sidebar and select Pull or Push directly.

26.4 Shielding the Repository: .gitignore

In biological research, your project folder will often contain massive raw datasets (like genomic sequence reads or large satellite images) and temporary system files.

Because AI agents can be eager to commit your work, you must set up a shield to prevent them from staging these files. We do this with a special file named .gitignore placed in the root directory.

26.4.1 Common Gotchas with .gitignore

  1. It Does Not Retroactively Ignore (The “Not Working” Gotcha): If a file has already been committed to Git in the past, adding it to .gitignore will not work. Git will continue tracking and committing any changes to that file. To make .gitignore work, you must first untrack the file (see the Tip below).
  2. No Direct Size Filtering: A .gitignore file filters by file name patterns (like *.csv), not by file size. However, GitHub has a strict size filter that rejects any push containing a file larger than 100 MB (and warns you for files over 50 MB). If you accidentally download a huge dataset file that is not matched by your .gitignore patterns, Git will try to track it.
    • Tip: Find large files in your terminal: You can search your project for any files larger than 50 MB by running:

      find . -type f -size +50M

26.4.2 A Best-Practice .gitignore for R Biologists

Create a text file named .gitignore in your repository root and add the following:

.Rhistory
.RData
.Ruserdata
.Rproj.user/

.DS_Store
Thumbs.db
How to Untrack a File Already Committed

If you accidentally committed a large file before adding it to your .gitignore, Git will keep tracking it. Tell Git to stop tracking it without deleting it from your computer by running:

git rm --cached data/large_dataset.csv

Alternatively, you can just ask your AI agent to do it:

“Stop tracking data/large_dataset.csv in Git, but keep the file on my computer.”