Git and GitHub at home
Your cmsc-120-lst project is a repository on GitHub, so the same files are on any machine you sit down at. Everything on this page is done from IDEA; none of it is the command line, and Git itself is not something this course teaches. Three verbs are all you need: commit, push, pull.
VS Code uses the Git it finds on the machine, so install Git first, from git-scm.com; on a Mac, the command line developer tools. Signing in to GitHub works as it does in IDEA, a browser tab and Authorize, and no key. Then:
- Log in and clone, in one go: the Source Control view (
Ctrl+Shift+G), Clone Repository, then Clone from GitHub. VS Code asks to sign in with GitHub: Allow, authorize in the browser tab that opens, and come back. Pick yourcmsc-120-lstfrom the list, and a folder for it. VS Code keeps the login and uses it for every push and pull after. - Commit and push: in Source Control, type your line in the message box, Commit, then Sync Changes, which pushes. The first time, it asks whether to stage all your changes and commit them: yes.
- Pull: the … menu in Source Control, Pull; or Sync Changes, which pulls and pushes in one go.
1. Once, on your own computer
- IDEA and Java. How to run Java says which Java the course uses and how IDEA gets it.
- Git. IDEA offers to download it the first time it is missing: Settings → Version Control → Git, the Download and Install button. On a Mac a window offers the command line developer tools instead; say yes.
- Log IDEA in to GitHub. Settings → Version Control → GitHub, the +, Log In via GitHub…. A browser tab opens; Authorize finishes it. Use the account that owns your
cmsc-120-lst.
2. Your project, at home
Once on each computer: File → New → Project from Version Control…, paste your repository’s address, from the green Code button on its page on GitHub, and Clone. Say yes to Load Maven project. After that it is in IDEA’s recent projects, as it is in the lab.
Check that it is yours: the address has your GitHub username in it, not cu-cs-labs. The template’s address clones too, but it has nowhere to push. And it starts with https://: if the Code button shows one starting with git@, switch its tab to HTTPS. The other kind wants an SSH key, which this page does not set up; if you would rather have one, CMSC 230’s page does: Getting into GitHub with an SSH key.
3. Commit and push, pull
Before you leave any machine: commit and push
Git → Commit… (Ctrl+K). Tick your files, write a line saying what you did, then Commit and Push… and Push. Then open your repository on GitHub: your line is at the top, with the time. If it is not there, the work is on this seat and nowhere else.
When you sit down anywhere: pull
Git → Pull…, then Pull. Your files are now what GitHub has, which is what you pushed last, wherever that was.
The habit: pull when you sit down, commit and push before you leave, at home and in the lab alike. A commit is a named point in your work; the push is what puts it on GitHub.
4. When it says no
- The push is rejected, with fetch first or rejected in the message: GitHub has work this machine does not, usually because you did not pull. Pull, then push again.
- A merge window with two versions of the same lines: the same line was changed in two places without a pull in between. Keep the side you want with the arrows, Apply, then commit and push.
- IDEA asks you to log in again: log in. A different seat is a different machine.
- Anything else: do not delete the project. Copy what IDEA says into the class channel.
5. In the lab
The lab’s IDEA asks you to log in to GitHub, as in step 3, the first time you push from a machine. The login stays with your own account on that machine, so a different seat asks once more.
6. No GitHub account
You can still clone the template, https://github.com/cu-cs-labs/cmsc-120-lst, and work in it; nothing you do there goes up. Take the file with you some other way: copy its text into the Journal, as Getting your work off the lab machine says, or email it to yourself. An account is two minutes at github.com/signup, with any email.