GitHub Workflow
This guide covers the standard GitHub workflow for course projects, from initial setup through submission.
Quick Reference
Action |
Command |
|---|---|
Clone repo |
|
Create branch |
|
Stage changes |
|
Commit |
|
Push |
|
Update from main |
|
Initial Setup
1. Fork the repository (if working on a shared project)
Click “Fork” in the top-right of the GitHub repository page. This creates your own copy.
2. Clone to your machine
git clone https://github.com/YOUR-USERNAME/repo-name.git
cd repo-name
The Branch Workflow
Never work directly on main. Always create a branch for your work.
1. Create a new branch
git checkout -b your-branch-name
Use descriptive names that reflect what you’re working on:
add-impact-analysisclean-sales-dataupdate-visualizationdraft-findings-section
2. Make your changes
Edit files, run your analysis, update notebooks.
3. Stage and commit
# Stage all changes
git add .
# Or stage specific files
git add analysis/impact_model.py
# Commit with a clear message
git commit -m "Add regression model for impact estimation"
Commit messages should:
Start with a verb (Add, Fix, Update, Remove, Clean)
Be specific about what changed
Be under 50 characters for the first line
4. Push to GitHub
git push origin your-branch-name
Creating a Pull Request
Go to your repository on GitHub
Click “Compare & pull request” (appears after pushing)
Fill in:
Title: Clear summary of changes
Description: What you did and why
Click “Create pull request”
Your teammates or instructor can now review your work.
Keeping Your Branch Updated
Before submitting, sync with the latest changes from main:
# Switch to main
git checkout main
# Pull latest changes
git pull origin main
# Switch back to your branch
git checkout your-branch-name
# Merge main into your branch
git merge main
Resolve any conflicts, then push again.
Common Scenarios
“I made changes on main by accident”
# Create a branch with your changes
git checkout -b my-changes
# Reset main to match remote
git checkout main
git reset --hard origin/main
“I need to undo my last commit”
# Keep changes, undo commit
git reset --soft HEAD~1
# Discard changes entirely
git reset --hard HEAD~1
“My branch has conflicts”
Pull the latest main:
git pull origin mainGit will mark conflicts in files with
<<<<<<<markersEdit files to resolve conflicts
Stage resolved files:
git add .Complete the merge:
git commit
Reproducibility and GitHub Actions
All course projects must achieve full reproducibility through GitHub Actions continuous integration. The repository template provides a reference implementation with the standard project structure and CI configuration.
What Happens When You Push
When you push to GitHub or create a pull request, GitHub Actions automatically runs:
GitHub detects your push or PR
Actions spins up a fresh virtual machine
Your
environment.ymlinstalls all dependenciesAutomated tests and checks run
You see ✅ (pass) or ❌ (fail) on your PR
Check the “Actions” tab in your repository to see run details and debug failures.
The environment.yml File
This file defines all software dependencies for the project. GitHub Actions uses it to create a consistent environment that ensures your analysis runs identically on any machine.
name: course-project
channels:
- conda-forge
- defaults
dependencies:
- python=3.11
- pandas
- numpy
- scikit-learn
- matplotlib
- jupyter
- pip
- pip:
- some-pip-package
Setting Up Your Local Environment
To match the GitHub Actions environment locally:
# Create environment from file
conda env create -f environment.yml
# Activate it
conda activate course-project
# Update if environment.yml changes
conda env update -f environment.yml --prune
Adding New Dependencies
If your code needs a new package:
Add it to
environment.ymlUpdate your local environment:
conda env update -f environment.ymlTest that everything still works
Commit the updated
environment.ymlwith your code
Never install packages manually without updating environment.yml — your code will fail in GitHub Actions if dependencies aren’t declared.
Long-Running Computations
When code execution spans multiple hours, you can pre-compute results and load them during CI runs. If you take this approach, include notebook explanations detailing why pre-computation is necessary and how the results were generated.
Project Submission Checklist
Before creating your pull request:
[ ] Code runs without errors
[ ] All notebooks execute top-to-bottom
[ ] Results are reproducible
[ ] Commit messages are clear
[ ] Branch is up-to-date with main
[ ] GitHub Actions checks pass ✅
[ ] New dependencies added to
environment.yml
Useful Commands
# Check status
git status
# View commit history
git log --oneline
# See what changed
git diff
# Discard local changes to a file
git checkout -- filename
# List branches
git branch -a
# Delete a local branch
git branch -d branch-name
Getting Help
git help <command>— Built-in documentationGitHub Docs — Official guides
Remember: Commit early, commit often. Small, focused commits are easier to review and debug than large, sweeping changes.