GIT CHEATSHEET for APCS
1. Starting a New Project
- On GitHub, partner1 creates a new repository w/
README.md
and .gitignore
file.
- On GitHub, partner1 goes to Gear (Settings) → Collaborators and invites partner2 to collaborate.
- On GitHub, partner2 accepts invitation.
2. Cloning a Repo on to your computer
- On GitHub, partner1's repository site, partner1 and partner2 both click on the green Code button and copy the URL listed there.
- If using a Terminal/BlueJ,
% git clone <URL clone link>
- If using VS Code, click on Source Control → Clone Repository and paste in URL.
3. Keeping your local version up-to-date
- 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.
- 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:
git add .
to stage the files
git commit -m "description goes here"
to make a local commit
- 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:
git switch main
to get onto the main branch
git pull
to update your main branch with any recent changes that your partner might have made
git merge <branchname>
to try to bring in your work from the development branch
- Manage any merge conflicts in the editor.
- 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.
- On your local machine, be sure to update your branch with the new
main
branch: git switch <branchname>
and then git merge main