This document provides a step-by-step guide for students working collaboratively on the git-collaboration-template project. Follow these instructions to learn how to work together using Git and GitHub.
Student A should complete this step:
- Navigate to the template repository on GitHub.
- Click the green "Use this template" button.
- Select "Create a new repository".
- Give your repository a name (e.g., "git-collaboration-project").
- Choose to make it public.
- Click "Create repository from template".
Student B should complete this step:
- Navigate to Student A's newly created repository.
- Click on the "Fork" button in the upper right corner to create a copy of the repository in your own GitHub account.
Both students can work with their repositories in two ways:
For both Student A and Student B:
- Navigate to your respective repository on GitHub (Student A uses the original, Student B uses the fork).
- Click the green "Code" button.
- Select the "Codespaces" tab.
- Click "Create codespace on main" or "+" to create a new codespace.
- Wait for the codespace to load - this may take a few minutes.
- Once loaded, you'll have a full development environment in your browser.
(Better for general use)
For both Student A and Student B:
-
Navigate to your respective repository on GitHub.
-
Click the green "Code" button and copy the repository URL.
-
Open your terminal or command prompt.
-
Use the following command to clone the repository:
git clone <repository-url>
-
Change into the project directory:
cd <your-repository-name>
For both Codespaces and Local:
Both students should create feature branches for their work:
git checkout -b feature/student-a-changesgit checkout -b feature/student-b-changesFor both Codespaces and Local:
- Each student should work on different parts of the project to avoid conflicts initially.
- Student A might modify
src/main.pywhile Student B works onsrc/utils/helpers.py. - Make your changes and save the files.
For both Codespaces and Local:
-
Stage your changes:
git add . -
Commit your changes with a descriptive message:
git commit -m "Add feature: descriptive message"
For both Codespaces and Local:
-
Push your changes to your respective repositories:
git push origin feature/your-branch-name
Or if working directly on main:
git push origin main
Student B should complete this step:
- Navigate to Student A's original repository on GitHub.
- You should see a prompt to create a pull request for your recently pushed changes.
- Click "Compare & pull request".
- Ensure the pull request is going from your fork to Student A's repository.
- Add a title and description for your pull request.
- Click "Create pull request".
Student A should complete this step:
- Navigate to the "Pull requests" tab in your repository.
- Click on the pull request created by Student B.
- Review the changes by clicking on the "Files changed" tab.
- Add comments or request changes if needed.
- If the changes look good, click "Merge pull request".
- Confirm the merge by clicking "Confirm merge".
- Optionally, delete the feature branch by clicking "Delete branch".
If you merged using a pull request and were working on a feature branch:
-
Switch to main branch:
git checkout main
-
Pull the latest changes:
git pull origin main
Codespaces and Local:
To keep your fork up to date with Student A's repository:
-
Add Student A's repository as an upstream remote (only needed once):
git remote add upstream <student-a-repository-url>
-
Fetch changes from upstream:
git fetch upstream
-
Switch to your main branch:
git checkout main
-
Merge upstream changes:
git merge upstream/main
-
Push updated main to your fork:
git push origin main
Both students can now continue the cycle:
- Create new feature branches
- Make changes
- Push changes
- Create pull requests
- Review and merge
- Sync repositories
Instead of forking, Student A can invite Student B as a collaborator:
Student A:
- Go to repository "Settings"
- Click "Manage access"
- Click "Invite a collaborator"
- Enter Student B's GitHub username
- Send invitation
Student B:
- Accept the invitation via email or GitHub notifications
- Clone Student A's repository directly (no fork needed)
- Both students can push to the same repository using branches
You have successfully completed the collaborative workflow! You've learned how to fork repositories, create pull requests, review code, and keep repositories synchronized. This workflow mirrors real-world collaborative development practices. Continue practicing with the exercises in the exercises directory to further enhance your Git and GitHub collaboration skills.