Activity - Git and GitHub
In this activity you’ll create a repo on GitHub and will share files with a partner.
- Choose a partner
- Partner 1 creates a repo on GitHub and invites Partner 2 (Partner 1 will need Partner 2’s GitHub ID)
- Log into GitHub and click on your icon in upper right, select “Your organizations”, choose cs50-2022-fall
- Click “New”, give repo a name, keep default settings (e.g., keep repo private), click “Create repository”
- Click “Add teams and collaborators” (near top), then “Add people”, enter Partner 2’s GitHub ID
- Give Partner 2 rights (Read, Triage, Write, Maintain, or Admin), choose Admin for today, then click “Add person to repository”
- Partner 1 pushes a file to GitHub
- Click on repo name in upper left corner, then SSH (in middle of screen), then copy icon to copy the URL (something like git@github.com:cs50-2022-fall/<repo name>.git)
- Change directory to where you’d like to store the code (e.g. ~/cs50 on plank)
- Git clone the repo and change directory:
git clone <repo>(ignore the warning that you’ve cloned an empty repo) lsto see a new directory was created, change directory into the repo’s directorycd <repo directory>- Create a README.md file in the directory and enters a few lines:
vi README.md - Run
git statusto see your README.md is not tracked - Tell Git to track it:
git add README.md - Run
git statusagain to see Git is tracking your new file - Run
git commit -m "Initial commit"to commit your file - Push the file to GitHub
git push -u origin main - Check on GitHub web interface the file appeared (refresh your browser!)
- Partner 2 makes changes
- Accept invitation email from GitHub
- From GitHub web page select Code, ensure SSH selected, then copy repo URL
- Get files with
git clone <repo URL>; - Run
lsto see new directory created, change into that directorycd <repo directory> - Run
lsagain to see README.md - Edit README.md
- Run
git statusto see README.md is modified, but not staged for commit - Tell git to include these changes in next commit
git add README.md - Run
git statusto see README.md is modified - Tell git to stage changes
git commit -m "<describe changes>" - Push changes to GitHub
git push -u origin main - Check via GitHub web interface that changes were pushed (refresh browser!)
- Partner 1 get changes made by Partner 2 with
git pull - Try to create a merge conflict by editing the same line
- Each partner edits README.md and pushes to GitHub
- First partner will succeed, second partner will get merge conflict (you may need to run
git config pull.rebase falseto specify how to handle conflicts if this is your first conflict) - Resolve the merge conflict by editing file with conflicting changes (the merge conflict message will say which files are in conflict)
- Push changes to GitHub