This repository has been modified from the original version created by Sam Cong. Anything below that references "I" is in reference to him, I am simply reproducing this for in-class demo purposes.
This repository serves as the in-class demo repository for Lab 3 of UChicago MACS 30112/30122 course. In this lab (see the shared Google Slide), I will walk through collaboration using git and github to help students better prepare for their final project. Specifically, I will mainly cover the three main ways of collaboration using git and github: 1) Only Push and Pull (on a Shared Main Branch), 2) Fork and Pull Requests, and 3) Branch and Merge. In addition, I will lay out some additional resources for both topics covered in the lab for reconsolidation and more advanced topics (beyond the scope of this lab) for exploration.
.
├── 1_Clone_and_Push # Directory containing test code for Only Push and Pull
├── 2_Fork_and_Pull_Request # Directory containing test code for Fork and Pull_Request
├── 3_Branch_and_Merge # Directory containing test code for Branch and Merge
├── Demo_Steps # Directory outlining steps of code implementation during in-class demo
Collaboration in Git can take different forms, each with its advantages and challenges. This guide covers three common collaboration approaches: Only Pull and Push, Fork and Pull Requests, and Branch and Merge.
This is the simplest but riskiest way to collaborate on a project. Team members clone the same repository, make changes locally, and push directly to the main branch.
- Clone the repository:
git clone https://github.com/example/repo.git
- Make changes, add, and commit:
git add <file> git commit -m "Your commit message"
- Push changes:
git push origin main
- Risk of overwriting teammates' work if they push before you.
- Frequent merge conflicts, especially if multiple people edit the same files.
- No built-in code review process, meaning bugs can get merged directly into
main.
🔹 Best for: Small projects with a few contributors, but not ideal for structured collaboration.
In this workflow, contributors fork the original repository, make changes in their own copy, and submit a pull request (PR) for review before merging.
- Fork the repository on GitHub.
- Clone the forked repo:
git clone https://github.com/your-username/repo.git
- Add the original repository as an upstream remote:
git remote add upstream https://github.com/original-owner/repo.git
- Make changes, commit, and push:
git add <file> git commit -m "Your commit message" git push origin main
- Open a pull request on GitHub from your fork to the original repository.
- The repository owner reviews and merges the PR.
✅ Prevents accidental overwrites by working in separate forks.
✅ Encourages code reviews before merging.
✅ Ideal for open-source projects and external contributions.
🔹 Best for: Open-source projects, external collaboration, and structured contributions.
Instead of working directly on main, developers create feature branches to work independently before merging changes.
- Create a new branch:
git checkout -b feature_branch
- Make changes, commit, and push:
git add <file> git commit -m "Your commit message" git push origin feature_branch
- Merge back into
mainwhen ready:- Fast-forward merge (if no divergence):
git checkout main git merge feature_branch
- 3-way merge (if branches diverged):
git merge --no-ff feature_branch
- Fast-forward merge (if no divergence):
- Delete the branch after merging:
git branch -d feature_branch git push origin --delete feature_branch
✅ Isolates features and bug fixes before merging.
✅ Allows parallel development without affecting main.
✅ Safer workflow compared to working directly on main.
- Requires branch management to keep things organized.
- Merge conflicts can still occur but are easier to resolve.
🔹 Best for: Team-based development and projects where multiple features are developed simultaneously.
| Method | Pros | Cons | Best For |
|---|---|---|---|
| Only Pull and Push | Simple, quick | High risk of conflicts & overwrites | Small projects, quick fixes |
| Fork and Pull Requests | Safe, structured, allows review | Slower, requires PR approval | Open-source projects, external contributors |
| Branch and Merge | Organized, enables parallel work | Needs branch management | Team development, feature-based workflows |
Each method has its use case, but for most structured development projects, Branch and Merge or Fork and Pull Requests are preferred over Only Pull and Push.
- Only Pull and Push is risky due to direct changes to
main. - Fork and Pull Requests enable safe contributions and review.
- Branch and Merge keeps the workflow organized and avoids conflicts.
I understand that using git and github for team collaboration may become challenging (and irritating 😑) at first, especially when you are trying as hard as you can to understand piles of unfamiliar git commands and those annoying "merge conflicts" error messages. This is in fact totally normal! It also applies to me when I started to learn these topics and apply them in my own group projects (and even today to be honest 😂).
To help streamline our Git learning experience, I have compiled a structured list of resources in this shared Google Document. The resources are grouped into broad topics, with each entry including a direct link and a brief comment on its content. The topics range from fundamental Git commands (commit, push, pull) to collborating using fork and pull requests and branch and merge and finally to more advanced concepts like merging, rebasing, undoing changes (e.g., reset vs. revert) and Git workflows. This collection includes both beginner-friendly and in-depth blogs, video walkthroughs, and even interative games (!) to cater to different learning preferences and levels. I hope this serves as a useful reference for both refreshing key concepts and deepening your understanding through hands-on challenges.