Git Team Exercise: Safe Collaboration
Git Exercise: Safe Collaboration with Multiple Students
This exercise walks through a safe Git workflow for a team of 4 students. Each student contributes a different type of file:
- Student 1: Data file (
data/raw/data.csv
) - Student 2: Data cleaning script (
src/data/clean_data.R
) - Student 3: Plot script (
src/figs/make_plot.R
) - Student 4: Quarto webpage (
pages/report.qmd
) referencing a saved PNG figure (figs/plot.png
)
The focus is on fetching before merging to avoid conflicts and working safely without overwriting.
Step 1: Clone the Repository
Each student first clones the repository:
git clone https://github.com/example-org/class-project.git
cd class-project
Step 2: Create or Switch to a Branch
Each student works on their own branch to avoid overwriting files.
git checkout -b student1-data # Student 1
# or
git checkout -b student2-cleaning # Student 2
# or
git checkout -b student3-plot # Student 3
# or
git checkout -b student4-report # Student 4
Step 3: Add Work in the Correct Folder
Student 1: Data file
# Save your file as data/raw/data.csv
git add data/raw/data.csv
git commit -m "Add raw data file"
Student 2: Data cleaning script
# Save your script as src/data/clean_data.R
git add src/data/clean_data.R
git commit -m "Add data cleaning script"
Student 3: Plot script
# Save your script as src/figs/make_plot.R
# Make sure it saves a PNG figure in figs/plot.png
git add src/figs/make_plot.R figs/plot.png
git commit -m "Add plot script and saved PNG"
Student 4: Quarto webpage
# Save your report in pages/report.qmd
# Make sure it references figs/plot.png in the text
git add pages/report.qmd
git commit -m "Add report referencing plot"
Step 4: Sync Safely with Remote Repository
Before pushing changes, always fetch first to see if others have updated the repo:
git fetch origin
If there are no new changes on the remote branch, you can push safely:
git push origin student1-data
If there are new changes, merge them into your branch before pushing:
git merge origin/main
⚠️ Warning: If you use git pull
directly, it automatically merges remote changes into your branch. This may create conflicts you aren’t ready to handle. Using git fetch
first is safer, because you see what’s new before merging.
Step 5: Merging into Main (Instructor or Team Lead)
The instructor (or team lead) will merge student branches into main
one at a time:
git checkout main
git fetch origin
git merge origin/student1-data
Repeat for student2-cleaning
, student3-plot
, student4-report
.
Summary of Safe Practices
- Work in separate branches.
- Place files in designated folders.
- Use
git fetch
before merging (safer than pull). - Only instructor merges to main.
- Avoid working directly on main branch.
Next Steps
After merging, open the webpage:
quarto render pages/report.qmd
This will include the cleaned data, generated figure, and student contributions combined.