18 Collaborating with Others
This chapter covers how to work on projects with collaborators using Git and GitHub.
18.2 The Collaboration Workflow
18.2.1 Before Starting Work
Always pull the latest changes:
git pullCheck for environment updates:
# Python - check if environment.yml changed
conda env update -f environment.yml
# R - check renv status
# renv::status()
# renv::restore()18.2.2 Making Changes
- Pull latest changes
- Do your work
- Stage and commit
- Push
git pull
# ... make changes ...
git add .
git commit -m "Add analysis for condition B"
git push18.2.3 When Collaborators Push
If someone pushed while you were working:
git pull
# May need to resolve conflicts (see below)
git push18.3 Branching Workflow
For larger changes, use branches:
18.3.1 Create a Branch
git checkout -b my-feature18.3.2 Work on the Branch
# Make changes, commit as usual
git add .
git commit -m "Add new analysis"18.3.3 Push the Branch
git push -u origin my-feature18.3.4 Create a Pull Request
- Go to the repository on GitHub
- Click Compare & pull request
- Add description of changes
- Request review from collaborator
- Merge when approved
18.3.5 After Merging
git checkout main
git pull
git branch -d my-feature # Delete local branch18.4 Handling Merge Conflicts
Conflicts happen when two people change the same lines.
Claude Code can explain merge conflicts and help you resolve them safely.
I have a merge conflict in
analysis.qmdwith these conflict markers: [paste the conflicting section]. My collaborator changed the threshold. Which should I keep?
Show the conflict markers and explain the context. Claude can help you understand what each version does and decide how to resolve it.
18.4.1 Recognizing a Conflict
git pull
# CONFLICT (content): Merge conflict in analysis.R
# Automatic merge failed; fix conflicts and then commit.18.4.2 Resolving Conflicts
Open the conflicted file. You’ll see markers:
<<<<<<< HEAD
# Your version
result <- calculate_mean(data)
=======
# Their version
result <- calculate_median(data)
>>>>>>> origin/mainEdit to keep what you want:
# Keep both approaches, or choose one
result_mean <- calculate_mean(data)
result_median <- calculate_median(data)Remove the conflict markers, then:
git add analysis.R
git commit -m "Resolve merge conflict in analysis.R"
git push18.5 Environment Synchronization
18.5.1 When You Add Packages
Python:
conda install new-package
conda env export > environment.yml
git add environment.yml
git commit -m "Add new-package to environment"
git pushR:
install.packages("new-package")
renv::snapshot()git add renv.lock
git commit -m "Add new-package to renv"
git push18.5.2 When Collaborator Adds Packages
After pulling:
Python:
conda env update -f environment.ymlR:
renv::restore()18.6 Best Practices
18.6.1 Communicate
- Tell collaborators what you’re working on
- Avoid working on the same files simultaneously
- Use issues to track tasks
18.6.2 Commit Often
Small, frequent commits are easier to merge than large changes.
18.6.3 Pull Before Push
git pull
git pushThis catches conflicts early.
18.6.4 Use .gitignore
Ensure everyone has the same .gitignore to avoid committing:
- Large data files
- Personal IDE settings
- System files
18.6.5 Document Changes
Update README and documentation when you change:
- How to run the analysis
- Environment dependencies
- Data requirements
18.7 Working with GitHub Issues
18.7.1 Creating Issues
Use issues to track:
- Bugs to fix
- Features to add
- Questions to resolve
Click New Issue on GitHub and describe the task.
18.7.2 Referencing Issues in Commits
Link commits to issues:
git commit -m "Fix normalization bug (closes #12)"This automatically closes the issue when merged.
18.8 Forking (For External Collaborators)
If someone isn’t a direct collaborator:
- They fork the repo (creates their copy)
- They make changes in their fork
- They open a pull request to your repo
- You review and merge
This is common for open-source contributions.
18.9 Checklist for Collaboration
Starting a collaborative project:
Daily workflow: