Content is user-generated and unverified.

Working with Claude Code and GitHub: A Practical Guide

Overview

This guide explains how to use Claude Code to develop R code that syncs with GitHub, and how to get that code running on your local machine.

The Big Picture

There are three locations your code lives:

GitHub (cloud)  ←→  Your Local Computer  →  R Session
    ↑                      ↑                    ↑
Claude Code           git pull/push         source()
pushes here           syncs these           loads code

Claude Code works directly with GitHub. Your local computer syncs with GitHub using Git. R runs code from your local files.


Part 1: Using Claude Code

The Interface

Claude Code has two input areas:

LocationPurposeWhen to Use
Top left boxStart a new sessionBeginning a new task
Bottom right boxContinue current sessionFollow-up questions, refinements

The left sidebar shows your session history. Click any session to view and continue it.

Starting a Task

In the top left box, describe what you want:

  • "Fix the DSP permutation procedure in qap_symmetric_homophily_test.R"
  • "Add a function to calculate network transitivity"
  • "Explain how the graph creation algorithm works"

Claude Code will read your repository files, make changes, and push them to GitHub.

Providing Context (e.g., PDFs)

Claude Code doesn't have an upload button. To share reference materials:

Option 1: Add files to your repository

  • Save the PDF or document in your repo (e.g., in a docs/ folder)
  • Claude Code can then read it directly

Option 2: Create a summary document

  • Create a markdown file summarizing the key methods/procedures
  • Save it in your repo (e.g., docs/dsp_method.md)
  • Reference it in your prompt: "See docs/dsp_method.md for the procedure to implement"

Option 3: Paste key excerpts

  • Copy the relevant section directly into your prompt
  • Good for short procedures or specific equations

Part 2: How Claude Code Uses Git Branches

Why Branches?

Claude Code doesn't modify your main code directly. Instead, it:

  1. Creates a new branch (e.g., claude/fix-dsp-permutation-qap-...)
  2. Makes changes on that branch
  3. Pushes the branch to GitHub

This keeps your main code safe until you review and approve changes.

What You'll See on GitHub

After Claude Code works, you'll see yellow banners like:

claude/fix-dsp-permutation-qap-... had recent pushes
                                    [Compare & pull request]

Part 3: Getting Changes to Your Local Computer

Step-by-Step: The Recommended Workflow

Step 1: Review and Merge on GitHub

  1. Go to your repository on GitHub
  2. Click the "Compare & pull request" button
  3. Review the changes (GitHub shows exactly what lines changed)
  4. If satisfied, click "Merge pull request"
  5. Click "Confirm merge"
  6. Optionally delete the branch when prompted

Step 2: Pull Changes Locally

Using the command line:

bash
cd /path/to/your/QAPtest    # Navigate to your repo folder
git pull                     # Download and merge changes

Using RStudio:

  • Go to the Git pane (usually top-right)
  • Click the Pull button (down arrow icon)

Using R directly:

r
setwd("/path/to/your/QAPtest")
system("git pull")

Step 3: Load the Code in R

r
source("qap_symmetric_homophily_test.R")

Alternative: Merge Locally (Advanced)

If you want to test changes before merging on GitHub:

r
# Download branch information from GitHub
system("git fetch origin")

# Merge the specific branch into your current branch
system("git merge origin/claude/fix-dsp-permutation-qap-...")

# After testing, push the merged result back to GitHub
system("git push")

Use this when you want to test changes locally before they appear on the main branch on GitHub.


Part 4: Common Scenarios

Scenario 1: Starting Fresh

If you don't have the repository on your computer yet:

bash
git clone https://github.com/StephenBorgatti/QAPtest.git
cd QAPtest

Or in R:

r
system("git clone https://github.com/StephenBorgatti/QAPtest.git")
setwd("QAPtest")

Scenario 2: Daily Workflow

  1. Open Claude Code
  2. Start a session with your task
  3. Let Claude Code make changes
  4. Go to GitHub → merge the pull request
  5. In R or terminal: git pull
  6. In R: source("your_file.R")

Scenario 3: Checking What Branch You're On

r
system("git branch")      # Shows local branches, * marks current
system("git status")      # Shows current branch and any uncommitted changes

Scenario 4: Discarding Local Changes

If you made local changes you want to throw away:

r
system("git checkout -- .")           # Discard all uncommitted changes
system("git pull")                    # Get latest from GitHub

Part 5: Troubleshooting

"Your local changes would be overwritten by merge"

You have uncommitted local changes. Options:

r
# Option A: Discard your local changes
system("git checkout -- .")
system("git pull")

# Option B: Stash your changes temporarily
system("git stash")
system("git pull")
system("git stash pop")    # Restore your changes

"Please commit your changes or stash them before you merge"

Same as above — you have local modifications that conflict with incoming changes.

Branch is Ahead/Behind

r
system("git status")    # Will tell you if you're ahead or behind
system("git pull")      # If behind, this catches you up
system("git push")      # If ahead, this pushes your commits

Quick Reference

TaskCommand
Get latest code from GitHubgit pull
See what branch you're ongit branch
See status of local changesgit status
Download branch info without merginggit fetch origin
Discard local changesgit checkout -- .
Clone a repositorygit clone <url>

Summary

  1. Claude Code pushes changes to GitHub branches
  2. GitHub is where you review and merge changes (via pull requests)
  3. git pull brings merged changes to your local computer
  4. source() loads the code into R

The key insight: Claude Code → GitHub → Local → R. Each arrow is a separate step.

Content is user-generated and unverified.
    Claude Code GitHub Workflow: Complete Integration Guide | Claude