Git-Friendly Architecture
marimo notebooks are stored as.py files, which provides significant advantages for version control:
- Plain text format: Easy to read, diff, and merge
- No JSON metadata: No hidden state or execution counts
- Standard Python syntax: Works with all Python tools
- Meaningful diffs: See actual code changes, not format noise
Notebook File Structure
A marimo notebook is a standard Python script:- Review changes in pull requests
- Track code evolution over time
- Merge contributions from multiple authors
- Revert problematic changes
Working with Git
Initializing a Repository
marimo notebooks work with standard Git workflows:Viewing Changes
Use standard Git commands to view notebook changes:Committing Notebooks
Commit notebooks like any other Python file:Diffing and Merging
marimo’s Python-based format makes diffing and merging straightforward.Understanding Notebook Diffs
When reviewing changes, focus on:- Cell content: The actual code logic within
@app.celldecorators - Cell dependencies: Changes to function parameters (e.g.,
def __(pd, np)) - Return values: What each cell exports (e.g.,
return df,) - Imports: New or modified dependencies
Merging Changes
merge branches using standard Git commands:Handling Merge Conflicts
When conflicts occur, they appear as standard Python code conflicts:- Editing the file to choose or combine changes
- Removing conflict markers (
<<<<<<<,=======,>>>>>>>) - Testing the notebook:
marimo edit notebook.py - Committing the resolution:
git add notebook.py && git commit
After resolving conflicts, always run the notebook to ensure cells execute correctly and dependencies are maintained.
Rebase Workflows
marimo notebooks work seamlessly with rebasing:Collaboration Workflows
marimo’s Git compatibility enables effective team collaboration.Pull Request Best Practices
When creating pull requests with notebook changes:1. Provide context in PR descriptions
1. Provide context in PR descriptions
Explain the analytical or scientific changes:
2. Keep PRs focused
2. Keep PRs focused
Limit each PR to a single analysis or feature:✅ One PR: Add new data cleaning pipeline✅ Separate PR: Add visualization for cleaned data❌ One large PR: Refactor, add features, change visualizations
3. Test before submitting
3. Test before submitting
Ensure the notebook runs completely:
4. Document dependencies
4. Document dependencies
If you add new packages, document them:Or use marimo’s package management to inline dependencies:
pyproject.toml
Code Review Tips
When reviewing notebook changes:- Reviewer
Focus on:
- Logic correctness: Are the data transformations valid?
- Cell dependencies: Do cells reference the right variables?
- Reactivity: Will cells update correctly when dependencies change?
- Performance: Are there expensive operations that could be optimized?
- Documentation: Are complex cells explained with comments?
Shared Configuration
Share team configurations usingpyproject.toml:
pyproject.toml
Git Workflow Patterns
Feature Branch Workflow
Trunk-Based Development
Release Workflow
Advanced Git Features
Git Hooks
Automate notebook quality checks with Git hooks:.git/hooks/pre-commit
.git/hooks/pre-commit
Git Attributes
Optimize Git operations for notebooks:.gitattributes
Git Ignore
Exclude marimo-specific temporary files:.gitignore
The global
~/.config/marimo/marimo.toml is user-specific and should not be committed. However, project-specific .marimo.toml or pyproject.toml configurations should be version controlled.Comparing with Jupyter Notebooks
marimo’s version control advantages over Jupyter:| Feature | marimo | Jupyter (.ipynb) |
|---|---|---|
| File format | Pure Python | JSON |
| Diff readability | ✅ Readable | ❌ Noisy metadata |
| Merge conflicts | ✅ Standard Python | ❌ JSON structure |
| Code review | ✅ Easy | ❌ Difficult |
| Execution order | ✅ Deterministic | ❌ Can vary |
| Hidden state | ❌ None | ⚠️ Can persist |
| Git tools | ✅ All work | ⚠️ Need special tools |
Converting from Jupyter
Convert Jupyter notebooks to marimo for better version control:Best Practices Summary
✅ Do
✅ Do
- Commit notebooks as
.pyfiles - Write descriptive commit messages about analytical changes
- Test notebooks before committing (run all cells)
- Use branches for experimental analyses
- Share configuration via
pyproject.toml - Review diffs carefully for cell dependencies
- Document complex analytical decisions in comments
- Use standard Git workflows (PRs, code review)
❌ Don't
❌ Don't
- Don’t commit
.marimo.tomluser configs (unless project-specific) - Don’t make unrelated changes in a single commit
- Don’t commit untested notebooks
- Don’t ignore merge conflicts without testing
- Don’t commit sensitive data or API keys
- Don’t use notebooks for compiled outputs (use scripts)
Troubleshooting
Notebook won't run after merge
Notebook won't run after merge
Cause: Merge conflict resolution broke cell dependenciesSolution:
- Open in marimo editor:
marimo edit notebook.py - Check for syntax errors or missing variables
- Verify cell dependencies in the dataflow graph
- Run cells individually to identify the issue
Large diffs for small changes
Large diffs for small changes
Cause: Auto-formatting or dependency reorderingSolution:
- Configure consistent formatting in
pyproject.toml: - Format before committing:
marimo format notebook.py - Ensure all team members use same marimo version
Sensitive data in commit history
Sensitive data in commit history
Cause: Accidentally committed data or credentialsSolution:
- Use BFG Repo-Cleaner or git-filter-repo to remove sensitive data
- Add data files to
.gitignore - Use environment variables for credentials (load from
.env) - Review commits before pushing:
git diff HEAD
Related Documentation
- Configuration - Sharing team configurations
- Debugging - Fixing issues in notebooks
- Package Management - Managing dependencies
- Scripts - Running notebooks as scripts