This tutorial covers the basics of using git with GitHub for CS 334 assignments.
commit and pushpullFor each programming assignment, you will receive an email invitation to join the assignment on GitHub Classroom. Click the link in the email to accept the assignment. This will create a private repository for you on GitHub containing the starter code.
If you do not receive the email, check your spam folder or ask the instructor.
Once you have accepted the assignment, you will see your repository on GitHub. You need to clone it to get a local copy on your computer.
Go to your repository page on GitHub and click the green "Code" button. Copy the URL shown (use HTTPS unless you have SSH keys set up).
Open a terminal and navigate to where you want to put your work, then run:
git clone <repository-url>
For example:
git clone https://github.com/williams-cs/cs334-lab1-YOURNAME.git
cd into the new directory to see your starter files:
cd cs334-lab1-YOURNAME
ls
commit and pushAs you work, you should periodically save snapshots of your code. Each snapshot is called a commit.
After making changes, commit them with a short description:
git commit -m "completed problem 1" -a
The -a flag tells git to include all modified files. The -m
flag specifies a commit message describing what you changed.
Your commits are saved locally. To upload them to GitHub, push:
git push
You should push regularly so your work is backed up on GitHub.
Note
If you create a brand new file, you need to tell git to track
it before committing:
git add newfile.lisp
git commit -m "added new file" -a
pullIf your partner has pushed changes (see below), you need to pull them to update your local copy:
git pull
Run git pull before you start working each time to make sure you
have the latest version.
If you and your partner have both edited the same lines of the same
file, git will report a merge conflict. Open the file in your
editor---you will see markers like <<<<<<<, =======, and
>>>>>>> showing both versions. Edit the file to resolve the
conflict, remove the markers, and then commit:
git commit -m "resolved merge conflict" -a
git push
For labs requiring a partner, one person accepts the assignment and then adds their partner as a collaborator:
Go to your repository on GitHub (e.g.,
https://github.com/williams-cs/cs334-lab1-YOURNAME).
Click Settings (the gear icon near the top).
Click Collaborators in the left sidebar.
Click Add people and search for your partner's GitHub username.
Your partner will receive an email invitation. Once they accept, they can clone and push to the same repository:
git clone https://github.com/williams-cs/cs334-lab1-YOURNAME.git
Both partners now work in the same repository. Remember to pull
before you start working and push when you are done.
"Updates were rejected" when pushing: This means your partner
has pushed changes you don't have yet. Run git pull first, then
try git push again.
Merge conflict: See the instructions in the pull section above.
Permission denied: Make sure you have been added as a collaborator on the repository and have accepted the invitation.
If you get stuck, ask the TAs or instructor for help.