GIT CHEATSHEET for APCS

1. Starting a New Project

  1. On GitHub, partner1 creates a new repository w/ README.md and .gitignore file.
  2. On GitHub, partner1 goes to Gear (Settings) → Collaborators and invites partner2 to collaborate.
  3. On GitHub, partner2 accepts invitation.

2. Cloning a Repo on to your computer

  1. On GitHub, partner1's repository site, partner1 and partner2 both click on the green Code button and copy the URL listed there.
  2. 1. If using a Terminal/BlueJ,  
    % git clone <URL clone link> 2. If using VS Code, click on Source Control → Clone Repository and paste in URL.

3. Keeping your local version up-to-date

  1. If there are updates to the origin (on GitHub) from someone else, update your local repository with git switch main, then git pull to update the main branch.
  2. Also, if you have a branch, switch to your development branch and use git merge main to get your branch up to date with the origin.

4. Updating your branch (& pushing to GitHub)

Once you've made changes on your own development branch:

  1. git add . to stage the files
  2. git commit -m "description goes here" to make a local commit
  3. Optionally, git push to update your branch on GitHub.

5. Merging a branch into the main

When you're ready to try to add your development into the main branch:

  1. git switch main to get onto the main branch
  2. git pull to update your main branch with any recent changes that your partner might have made
  3. git merge <branchname> to try to bring in your work from the development branch
  4. Manage any merge conflicts in the editor.
  5. Once the merge has been accomplished on your local machine, confirm that you're on the main branch and use git push to update the GitHub server.
  6. On your local machine, be sure to update your branch with the new main branch: git switch <branchname> and then git merge main