How to use Git with Google Colab for real projects

Google Colab · Git · Approx. 9 min read

Colab is great for experiments, but serious ML work lives in Git. Here’s a practical workflow to clone repos, commit changes, and combine Git history with NoteCapsule Capsules for reproducible work.

1. Clone your repo into Colab

!git clone https://github.com/your-username/your-repo.git
%cd your-repo

For private repos, use a personal access token instead of your password, or mount Drive and sync locally via your laptop.

2. Set your Git identity inside Colab

!git config user.name "Your Name"
!git config user.email "you@example.com"

3. Edit notebooks and code, then commit

After making changes:

!git status
!git add notebook.ipynb src/
!git commit -m "Run experiment with new hyperparameters"

Push changes back to GitHub:

!git push origin main

4. Handle notebooks in Git

To keep diffs manageable:

5. Add NoteCapsule for runnable checkpoints

Git shows history; Capsules capture “this exact state runs end-to-end”. After a good run in Colab, create a Capsule and commit its metadata.

from notebookcapsule import create_capsule

create_capsule(
    name="after-git-experiment-1",
    notebook_path="notebooks/experiment.ipynb",
    data_dirs=["./data", "./models"],
    base_dir=".",   # repo root
)

Commit the Capsule metadata (or even the full Capsule folder, if small) so reviewers know exactly which state produced your results.

Git for history, NoteCapsule for runnable states

NoteCapsule complements Git in Colab: you keep all the usual commits and branches, and add Capsules at key milestones so future you (or your team) can reproduce important runs without guesswork.

Join NoteCapsule early access