Skip to contents

Introduction

thoth provides a tidyverse-friendly interface to Git operations, allowing you to manage version control directly from your R environment. This integration streamlines the version control workflow while maintaining the power and flexibility of Git.

Core Git Functions

Repository Status and Changes

Monitor and manage changes in your repository:

library(thoth)

# Check repository status
git_status()

# Stage changes
git_add("analysis.R")                                    # Single file
git_add(c("data/processed/results.csv", "README.md"))   # Multiple files
git_add(".", force = FALSE)                             # All changes

# Commit changes
git_commit("Add initial analysis")                      # Commit staged changes
git_commit("Update results", all = TRUE)                # Stage and commit all changes

Branch Management

Create and manage branches efficiently:

# View branches
git_branch_list()                    # Local branches
git_branch_list(all = TRUE)          # Include remote branches

# Create and switch branches
git_branch("feature/analysis")       # Create new branch
git_checkout("main")                 # Switch branch
git_checkout("feature/fix",          # Create and switch
             create = TRUE)

Remote Operations

Synchronize with remote repositories:

# Sync changes
git_pull()                          # Get latest changes
git_push()                          # Push local changes

# Work with specific remotes/branches
git_pull("origin", "main")
git_push("origin", "feature/analysis")

Integration with DVC

thoth’s Git functions work seamlessly with DVC for complete version control:

# Track data with DVC
dvc_add("data/raw/dataset.csv")

# Version control the tracking file
git_add("data/raw/dataset.csv.dvc")
git_commit("Add dataset tracking")

# Sync everything
git_push()      # Push Git changes
dvc_push()      # Push data to remote storage

Best Practices

1. Commit Structure

  • Make focused, single-purpose commits
  • Write clear, present-tense commit messages
  • Include context when necessary

2. Branch Management

  • Use feature branches for new work
  • Keep the main branch stable
  • Clean up merged branches

3. Workflow Integration

# Example analysis workflow
git_checkout("feature/new-analysis", create = TRUE)

# Do analysis work...

git_add("R/analysis.R")
git_commit("Add data processing function")
git_push()

Common Workflows

Feature Development

# Start new feature
git_checkout("main")
git_pull()
git_checkout("feature/analysis", create = TRUE)

# Work on feature...
git_add(".")
git_commit("Implement new analysis")
git_push()

Quick Fixes

# Create fix branch
git_checkout("main")
git_checkout("fix/issue-123", create = TRUE)

# Make changes...
git_add("R/functions.R")
git_commit("Fix calculation error")
git_push()

Next Steps